点击没有任何反应

时间:2019-09-06 07:28:38

标签: html angular

const link = '<a href="javascript:void(0);" (click)="redirectToPage(store)" class="btn grey">' + displayText + '</a>';

当我单击页面中的按钮时,什么也没发生。我哪里出问题了?我正在使用角度7。

redirectToPage(store){
alert('take me to store');
}

1 个答案:

答案 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');
  }
}

请参见Stackbiltz Demo