angular - Angular2 Observable Filter -


i'd filter observable, getting unexpected results.

i using following import statements:

import {observable} 'rxjs/observable'; import 'rxjs/add/observable/of'; 

this example returns nothing:

observable.of([0, 1, 2, 3, 4, 5]) .filter((x: any) => x % 2 === 0) .subscribe(data => console.log(data)); 

this example returns entire result set [0,1,2,3,4,5]:

observable.of([0, 1, 2, 3, 4, 5]) .filter((x: number[], idx) => x[idx] % 2 === 0) .subscribe(data => console.log(data)); 

does see syntax errors and/or missing? thank you!

you need use from if want pass values iterable (array in current case)

import 'rxjs/add/observable/from';  observable.from([0, 1, 2, 3, 4, 5]) .filter((x: any) => x % 2 === 0) .subscribe(data => console.log(data)); 

or if want stick of pass values arguments

observable.of(0, 1, 2, 3, 4, 5) .filter((x: any) => x % 2 === 0) .subscribe(data => console.log(data)); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -