Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度2执行间隔可观测_Angular - Fatal编程技术网

Angular 角度2执行间隔可观测

Angular 角度2执行间隔可观测,angular,Angular,假设我有以下代码: let sub = Observable.interval(1000).map((x) => { let date1= Math.floor(new Date().getTime()/1000); this.diff = date2 - date1; }).subscribe((x) => { }); observable工作得很好,每秒钟执行一次,但我的问题是,即使它是第一次执行,它也会等待一秒钟

假设我有以下代码:

let sub = Observable.interval(1000).map((x) => {
           let date1= Math.floor(new Date().getTime()/1000);
            this.diff = date2 - date1;
    }).subscribe((x) => { 
    });
observable工作得很好,每秒钟执行一次,但我的问题是,即使它是第一次执行,它也会等待一秒钟

我需要执行observable,然后以1秒的间隔上诉。如何使用angular 2实现这一点?

这可能有效(不确定):


在哪里定义了
date2
?谢谢,它是
startWith
let sub = Observable.interval(1000).startWith(0).map((x) => {
    let date1= Math.floor(new Date().getTime()/1000);
        this.diff = date2 - date1;
    }).subscribe((x) => { 
});