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

When I am clicking on the button in the page than nothing happens. Where am I getting wrong? I am using angular 7.

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

1 Answers1

0

Try like this:

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

See Stackbiltz Demo

Adrita Sharma
  • 21,581
  • 10
  • 69
  • 79