1

我在运行时从数据库中提取了一个与 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 {
/* . . . */
}
4

1 回答 1

0

Angular 6 用一个叫做Angular Elements的新特性解决了这个问题。

于 2018-05-10T07:45:16.223 回答