Ionic3标签(例如单击功能)在InnerHTML中不起作用

时间:2018-10-08 07:10:13

标签: javascript angular ionic3 innerhtml

离子标记在离子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);
 }
}

任何帮助,非常感谢

0 个答案:

没有答案