离子标记在离子3中不起作用。例如,(点击)方法不适用于[innerHTML]。下面是我的代码。
@IonicPage()
@Component({
selector: 'page-html-test',
templateUrl: 'html-test.html',
})
export class detailNewsPage {
html: any;
constructor(public navCtrl: NavController,
public navParams: NavParams,
) {}
ionViewDidLoad() {
this.detailNews = `<button ion-button (click)="detailNews1()">Test</button>`;
}
detailNews1(){
console.log('test-detailNews1 button clicked');
}
}
**htmlTest.html:**
<ion-content padding>
<div [innerHTML]="detailNews | safeHtml"></div>
</ion-content>
**safeHtml.ts**
@Pipe({
name: 'safeHtml',
})
export class SafeHtmlPipe implements PipeTransform {
/**
* Takes a value and makes it lowercase.
*/
constructor(private sanitizer:DomSanitizer){}
transform(html) {
return this.sanitizer.bypassSecurityTrustHtml(html);
}
}
任何帮助,非常感谢