const link = '<a href="javascript:void(0);" (click)="redirectToPage(store)" class="btn grey">' + displayText + '</a>';
当我单击页面中的按钮时,什么也没发生。我哪里出问题了?我正在使用角度7。
redirectToPage(store){
alert('take me to store');
}
答案 0 :(得分:0)
尝试这样:
import { DomSanitizer } from '@angular/platform-browser';
export class AppComponent {
constructor(private sanitizer: DomSanitizer) {
Window["AppComponent"] = this;
this.link = this.sanitizer.bypassSecurityTrustHtml('<a href="javascript:void(0);" onClick="Window.AppComponent.redirectToPage(`store`)" class="btn grey">' + this.displayText + '</a>');
}
displayText:any = "ABC"
link
redirectToPage(store) {
alert('take me to store');
}
}