takeWhile
signature: takeWhile(predicate: function(value, index): boolean, inclusive?: boolean): Observable
takeWhile(predicate: function(value, index): boolean, inclusive?: boolean): ObservableEmit values until provided expression is false.
Examples
// RxJS v6+
import { of } from 'rxjs';
import { takeWhile } from 'rxjs/operators';
//emit 1,2,3,4,5
const source$ = of(1, 2, 3, 4, 5);
//allow values until value from source is greater than 4, then complete
source$
.pipe(takeWhile(val => val <= 4))
// log: 1,2,3,4
.subscribe(val => console.log(val));Related Recipes
Additional Resources
Last updated