【发布时间】:2019-07-04 01:30:00
【问题描述】:
我想在运行时使用 innerHTML 将一个函数绑定到注入的 html 中。 我的组件
@Component({
selector: 'my-app',
template: `<div [innerHtml]="myHTML | safeHtml"></div>`,
styleUrls: ['/my-app.css'], encapsulation: ViewEncapsulation.ShadowDom
})
export class MyApp implements OnInit {
myHTML = `<button (click)="clickMe()" type="button" class="btn btn-secondary">+</button>`
constructor() {}
clickMe() {
console.log("Function is binded using the inner html tag")
}
}
我试过了,但它似乎不起作用。我不确定我是否遗漏了什么。任何帮助表示赞赏
【问题讨论】:
-
您可能需要检查
dynamic component loader以获取此信息。