RxJS operators for Observable emitted values
Emit only those observable values which match with the filter condition.
Example: In below example, we use range and filter together, range operator is using to generate sequential values from 0 to100 and filter operator accept range operator output value and filter according to specified condition (values must be completely divisible to 5). So this code will generate values from 0 to 100 which are divisible by 5 only. Subscribe method is used to display observable output on the console.
var ob1 = Rx.Observable.range(0,100).filter((val) => val%5==0).subscribe(val => console.log(val));
From is used to create observable from another object who generate multiple values like array object.
In this example, array1 items are read by observable.
// Example to create observable from the array using from an operator
var array1 = ['item1', 'item2', 'item3'];
var createobusingarray = Rx.Observable.from(array1).subscribe(x=>console.log(x));
create an Observable that emits a sequence of integers spaced by a given time interval.
here I am taking only 10 integer sequence with the help of RxJS take the operator
var intervalex = Rx.Observable.interval(500).take(10).subscribe(x=> console.log(x));
of operator of RxJS is used only to generate single item only.
var ofex = Rx.Observable.of(1000).subscribe(x=> console.log(x));
Repeat operator in angular is used to repeat observable output values.
var repeatinangular = Rx.Observable.range(1,5).repeat(2).subscribe(x=>console.log(x));
// output - 1,2,3,4,5,1,2,3,4,5,1,2,3,4,5
First value after 1/2 second, other sequence value after 1 second.
var bufferex1 = Rx.Observable.timer(500,1000).subscribe(x=> console.log(x));
buffer operator is used to showing values together, a buffer may not be applied on observable, we have to use with other rxjs operators like a timer.
var bufferex = Rx.Observable.timer(0,500).buffer(Rx.Observable.timer(1000,2000)).subscribe(x=> console.log(x));