A map operator
Similar to the familiar Array.prototype.map
method, this operator applies the projection function to each value and emits the projected result in the output Observable.
Import{Component, OnInit} from' @angular/core ';Import{Observable} from' rxjs/observable ';Import{of} from' rxjs/observable/of ';Import{Map} from' Rxjs/operators/map '; @Component ({selector:' App-convert ', Templateurl:'./convert.component.html ', Styleurls: ['./convert.component.css ']}) exportclassConvertcomponentImplementsOnInit {constructor () {} ngoninit () {of (1, 2). Pipe (Map val = val * 10). Subscribe (Val={Console.log (val); }); }}
two switchmap operator
Map each source value to Observable and output the newly generated internal Observable.
When the source value changes, stop the old observable and its subscriptions, and output the new observable.
Import{Component, OnInit} from' @angular/core ';Import{Observable} from' rxjs/observable ';Import{interval} from' Rxjs/observable/interval ';Import{Map} from' Rxjs/operators/map ';Import{Switchmap} from' Rxjs/operators/switchmap '; @Component ({selector:' App-convert ', Templateurl:'./convert.component.html ', Styleurls: ['./convert.component.css ']}) exportclassConvertcomponentImplementsOnInit {constructor () {} ngoninit () {interval (5000). Pipe (Switchmap (Val= Interval (1000). Pipe (Map (Val2= val * 100 +val2)) ). Subscribe (Val={Console.log (val); }); }}
RXJS conversion operator (angular environment)