如何向innerHTML中已设置的点击事件传入参数?
成分
html = "Lorem ipsum dolor sit amet, <mark (click)='hello('my name is what')'>consectetur adipiscing elit</mark>"
constructor(private changeDetectorRef: ChangeDetectorRef) {}
ngAfterContentChecked() {
this.changeDetectorRef.detectChanges();
if (this.showcaseContentText.nativeElement.querySelector('mark')) {
this.showcaseContentText.nativeElement
.querySelector('mark')
.addEventListener('click', this.hello.bind(this));
}
}
hello(test: string) {
console.log(test);
}
模板
<div class="text-md-left text-muted mb-lg-6" [innerHTML]="html" style="font-size: 15px"></div>
慕的地10843
相关分类