使用angular2-toaster

时间:2017-08-02 07:52:06

标签: angular angular2-toaster

所以我使用angular2-toaster packages,我总是收到双重通知。下面是使用此软件包的示例。

我不知道为什么会发生这种情况,但我知道如果我在浏览器中重新加载我的angular2应用程序,则此问题会被修复。有人知道问题出在哪里吗?

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

如果您需要更多其他部分的代码,请发表评论,我会发送。

1 个答案:

答案 0 :(得分:0)

对于所有遇到相同问题的人,这里有一些检查点可以检查可能会导致问题的原因。

  1. 如果将烤面包机与服务器响应结合使用,则OPTIONS可能还会触发烤面包机
  2. 如果您在服务和组件中使用烤面包机,请确保它不会触发两次
  3. 应该在您应用的app.module上设置Toaster配置