你可以使用clickHandler
.
@Component({
selector: 'my-app',
template: `
<div>
<toaster-container [toasterconfig]="config1"></toaster-container>
<button (click)="popToast()">pop toast</button><br/>
</div>
`,
})
export class App {
private toasterService: ToasterService;
constructor(toasterService: ToasterService) {
this.toasterService = toasterService;
}
popToast() {
var toast: Toast = {
type: 'info',
title: 'Here is a Toast Title',
body: 'Here is a Toast Body',
showCloseButton: true,
clickHandler: (t, isClosed): boolean => {
console.log('i am clicked..', isClosed, t);
// got clicked and it was NOT the close button!
if (!isClosed) {
}
return true; // remove this toast !
}
};
this.toasterService.pop(toast);
}
}
现场演示:http ://plnkr.co/edit/uL98EbfIBd6pm7bMU80V?p=preview