2017-07-21 42 views
1

搜索小時後......大多數的例子是這樣的...rxjs takeuntil,檢查直至觀察到的源是有效

var source = Rx.Observable.timer(0, 1000) 
    .takeUntil(Rx.Observable.timer(5000)); 

var subscription = source.subscribe(
    function (x) { console.log('Next: ' + x); }, 
    function (err) { console.log('Error: ' + err); }, 
    function() { console.log('Completed'); }) 

結果

Next: 0 
Next: 1 
Next: 2 
Next: 3 
Next: 4 
Completed 

但是,我婉知道的是有可能從源值檢查不是另一個可觀察的對象..這樣的事情..

var source = Rx.Observable.timer(0, 1000) 
    .takeUntil((result) => result == 5); 

回答

2

我猜你是什麼樣子ing for是takeWhile

var source = Rx.Observable.timer(0, 1000) 
    .takeWhile((result) => result < 5); 

source.subscribe(
    (val) => console.log(val), 
    (err) => console.log(err), 
    () => console.log('complete') 
);