我想在 div 标签中附加 htmlString 。
app.component.ts文件,
public htmlString:string = '';
this.htmlString:string = '<img id="img" src="assets/imgages/image.jpg">
<script>
document.getElementById("img").onclick = function(){
alert('click on image');
};
</script>';
app.component.html
<div></div>
我使用了下面的代码,但脚本以纯文本形式返回。
<div [innerHTML]="htmlString"></div>
如何解决?