角度5重置计时器可忽略

时间:2018-07-14 05:56:24

标签: jquery typescript angular5

我在几分钟后有超时模式,有时我需要将角度5中的时间重置clearInterval()不起作用,所以我使用了可观察的计时器,但是unsubscribe()subject.next()未重置时间。。。

export class TimeOutModalService extends ServiceBase {
subject: Subject<{}>;
timer: Observable<number>;
finished: boolean;
intervalObj = undefined;

constructor() {
super();
this.subject = new Subject();

}
create() {

    this.timer =  Observable.interval(10000);
    this.intervalObj = this.timer.subscribe(() => {
        this.callback();
    });
};
callback() {
    $('#time-out-modal #window-modal').modal({ backdrop: 'static', keyboard: false, show: true })
}

reset = () => {
    if (this.intervalObj) {
        this.intervalObj.unsubscribe();
    }
    this.create();
};

}

0 个答案:

没有答案