Angular Function call inside toaster not working

Viewed 124

Please I want to call a function inside a toaster. When I put an a href link it work but button no. When I put the button outside the toastr the function call it work. Thanks.

 this.toastr.toastrConfig.enableHtml=true;
 this.toastr.info(" <button type='button' (click)='this.exportexcel()'>click here</button> ");

  exportexcel(): void
    {
console.log('text')
    }

I have tried this its not working also inside the toaster but outside it work.

<a style='cursor: pointer' (click)='this.exportexcel()'> cloud_download</a>
1 Answers

I do not know how to call function when click on the button created on the content, but you can override toastr properties.

At this case, I overrided the "onclick" propert, so when you click anywhere in the alert (except the close button), I call a funtion:

this.toastr.toastrConfig.enableHtml=true;
this.toastr.info(
  '<button type="button"> Click at this alert </button>', // Content
  'Export excel', // Title
  { onclick: () => this.exportexcel() }, // Override properties
);

exportexcel(): void {
  console.log('text')
}
Related