如何在运行时生成带有字符串的 Angular 组件?

How to generate an Angular component with string at runtime?

我在运行时从数据库中提取了一个 属性,它对应于一个 Angular 选择器。

this.stringSelector = "<app-hello></app-hello>";

像这样呈现 "Hello World" 的最佳方式是什么?

<app-root>
  <app-hello></app-hello>
</app-root>

这仅适用于 html 标签,不适用于 Angular 选择器:

<app-root>
  <div [innerHTML]="this.stringSelector | safe: 'html'"></div>
</app-root>

app-hello 组件只做一件事:

@Component({
  selector: 'app-hello',
  template: `<h1>Hello World</h1>`
})
export class HelloComponent {
/* . . . */
}

Angular 6 用名为 Angular Elements 的新功能解决了它。