angularangular2-toaster

double notification with angular2-toaster


So i use the the angular2-toaster packages and i always recieve double notifications. below is an example for the use of this package.

I dont know why this happens, but i know if i reload my angular2 app in the browser this problem is fixxed. Does someone know where the problem is?

Promotion.service.ts

private toasterService: ToasterService;

public toasterconfig : ToasterConfig =
    new ToasterConfig({
        tapToDismiss: true,
        timeout: 5000
});

constructor(
    private ApiClientService: ApiClientService,
    toasterService: ToasterService
) {
    this.toasterService = toasterService;
}
postVoucher(payload: JSON){

    let serviceDec = "voucher";
    let response;
    let status;
    let title;
    let text;
    //console.log(JSON.stringify(payload));;
    return this.ApiClientService.postAPIObject(serviceDec, payload).then((response) => {
        //console.log(response['response_payload']['id']);
        if(response['status']['statusCode']==0){
            this.router.navigate(['/Promotion', response['response_payload']['id']]);
            status = 'success';
            title = 'Erledigt!';
            text = 'Promotion erstellt';
        } else {
            status = 'error';
            title = 'Fehler';
            text = 'Promotion konnte nicht erstellt werden';
        }
        this.toasterService.pop(status, title, text);
    });
}

If you need more Code of other parts, just leave a comment and i will deliver.


Solution

  • For all out there who has the same problem, here are some checkpoints to check which may run the problem.

    1. If you use the toaster in combination with server responses, OPTIONS also may trigger toaster
    2. If you use the toaster in a service and a component, make sure it doesnt trigger twice
    3. The Toaster config should be set at the app.module of your App