[英]How to generate an Angular component with string at runtime?
I have a property pulled from database at runtime that correspond to an Angular selector. 我在运行时从数据库中提取了一个与Angular选择器相对应的属性。
this.stringSelector = "<app-hello></app-hello>";
What is the best way to render "Hello World" like so? 像这样渲染“ Hello World”的最佳方法是什么?
<app-root>
<app-hello></app-hello>
</app-root>
This is good only for html tags, not Angular selectors: 这仅适用于html标签,而不适合Angular选择器:
<app-root>
<div [innerHTML]="this.stringSelector | safe: 'html'"></div>
</app-root>
The app-hello component does just one thing: app-hello组件仅做一件事:
@Component({
selector: 'app-hello',
template: `<h1>Hello World</h1>`
})
export class HelloComponent {
/* . . . */
}
Angular 6通过称为Angular Elements的新功能解决了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.