RXJS conversion operator (angular environment)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.