One of the operators
Import{Component, OnInit} from' @angular/core ';Import{of} from' rxjs/observable/of ';Import{Observable} from' rxjs/observable '; @Component ({selector:' App-create ', Templateurl:'./create.component.html ', Styleurls: ['./create.component.css ']}) exportclassCreatecomponentImplementsOnInit {constructor () {} ngoninit () {//Create from ArrayConst ARR= [' Red ',' Yellow ',' Blue ']; Const Colors:observable<string[]> =of (arr); Colors.subscribe ((colorsarr:string[])={console.log (Colorsarr); }); //creating from an iterator objectConst MAP:MAP<string, any> =NewMap (); Map.Set(' Fruit ',' Orange '); of (map). Subscribe (Fruitsmap:map<string, any>) ={console.log (FRUITSMAP); } ); }}
Two from operator
Import{Component, OnInit} from' @angular/core ';Import{from} from' Rxjs/observable/from ';Import{Observable} from' rxjs/observable '; @Component ({selector:' App-create ', Templateurl:'./create.component.html ', Styleurls: ['./create.component.css ']}) exportclassCreatecomponentImplementsOnInit {constructor () {} ngoninit () {//Create from ArrayConst ARR= [' Red ',' Yellow ',' Blue ']; Const Colors:observable<string> =From (arr); Colors.subscribe ((color:string)={console.log (color); }); }}
Three interval operators
Returns a sequence of infinite self-increment integers starting at 0, sent at each fixed interval. The first time did not send immediately, but the first period after the issue.
Import{Component, OnInit} from' @angular/core ';Import{interval} from' Rxjs/observable/interval ';Import{Observable} from' rxjs/observable '; @Component ({selector:' App-create ', Templateurl:'./create.component.html ', Styleurls: ['./create.component.css ']}) exportclassCreatecomponentImplementsOnInit {constructor () {} ngoninit () {interval (). Subscribe (val: Number) ={Console.log (val); }); }}
RXJS creation operator (angular environment)