当我点击 <a...
时我的函数没有被调用标签。
我的组件中有以下代码:
public htmlstr: string;
public idUser:number;
this.idUser = 1;
this.htmlstr = `<a (click)="delete(idUser)">${idUser}</a>`;
public delete(idUser){
alert("id " + idUser);
}
我的html
<div [innerHTML]="htmlstr"></div>
但是函数delete
未调用且不显示警报。
<div...
是动态创建的
最佳答案
如果有人遇到同样的问题,最重要的是答案不起作用,请尝试我的技巧:
在 HTML 中:
<button onclick="Window.myComponent.test()"> test </button>
在组件中:
class
constructor(){
Window["myComponent"] = this;
}
test(){
console.log("testing");
}
关于html - (单击)事件在 innerHtml 字符串 Angular 4 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48817261/