首页 > 解决方案 > Notify second message after first message is hidden

问题描述

I want to show wait message and after wait message is disapper then only I want to show error message or success message. At the moment the code below I tried, wait message comes and inbetween error message appears.

How can I fix this?

import { SnotifyService } from 'ng-snotify';
export class RequestResetComponent implements OnInit {
    constructor(
        private notify: SnotifyService,
        private user: UserService
    ) { }

    onSubmit = function () {
        this.notify.info('Wait...', {timeout: 2000});
        this.user.sendPasswordRestLink(this.form)
            .subscribe(
                res => this.handleResponse(res),
                err => this.notify.error(err.error.error)
            );
    }
}

标签: angularngnotify

解决方案


使用 setTimeout 显示错误或成功消息。我在错误消息中应用了超时,请参考。

import { SnotifyService } from 'ng-snotify';
export class RequestResetComponent implements OnInit {
    constructor(
        private notify: SnotifyService,
        private user: UserService
    ) { }

    onSubmit = function () {
        this.notify.info('Wait...', {timeout: 2000});
        this.user.sendPasswordRestLink(this.form)
            .subscribe(
                res => this.handleResponse(res),
                err => { let clearTimeOut = window.setTimeout(()=>{window.clearTimeout(clearTimeOut); this.notify.error(err.error.error)},3000);}
            );
    }
}

如果有任何问题,请告诉我。


推荐阅读