bla*_*awk 4 javascript reactive-programming rxjs rxjs5 angular
我正在使用这个但是区间运算符想要在可观察对象上它不存在于范围内,是否有一种方法可以发出例如发出60个整数,间隔为1秒的可观察对象,我一直在这样做
this.clock = Observable.range(1,60);
this.clock = this.clock.interval(1000).map(function(value){
console.log(value)
return value;
})
Run Code Online (Sandbox Code Playgroud)
它说间隔不是一个功能
还试过这个:
this.clock = Observable.range(1,60).interval(1000).map(function(value){
console.log(value)
return value;
})
Run Code Online (Sandbox Code Playgroud)
要使序列从1到60,时间间隔为1秒:
Observable
.interval(1000)
.map(x => x + 1) // to start from 1 instead of 0
.map(x => console.log(x)) // do some logic here
.take(60)
.subscribe();
Run Code Online (Sandbox Code Playgroud)
这里的输出是:
1
2
3
.
.
.
58
59
60
Run Code Online (Sandbox Code Playgroud)
这是一个可以运行以查看输出的代码段:
// just to have the working demo on SO
let output = '';
let divToUpdate = document.getElementById('counter');
// observable
Rx.Observable
.interval(1000)
.map(x => x + 1) // to start from 1 instead of 0
.map(x => {
output = `${output}<br>${x}`;
divToUpdate.innerHTML = output;
})
.take(60)
.subscribe();Run Code Online (Sandbox Code Playgroud)
<div id="counter"></div>
<script src="https://npmcdn.com/rxjs@5.0.0-beta.7/bundles/Rx.umd.js"></script>Run Code Online (Sandbox Code Playgroud)
var clock = Observable
.interval(100)
.take(60)
.map(function(value){
console.log(value)
return value;
});
Run Code Online (Sandbox Code Playgroud)
使用take(计数)。