Rxjs creation operator (Angular environment)

an of operator

Creates an Observable from an array, array-like object, Promise, iterator object, or Observable-like object.

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']
})
export class CreateComponent implements OnInit {

  constructor() { }

  by OnInit () {

    // create from array 

    const arr = [ 'red' , 'yellow' , 'blue' ];
    const colors: Observable<string[]> = of(arr);
    colors.subscribe((colorsArr: string[]) => {
      console.log(colorsArr);
    });

    // Create 
    const map from iterator object
 : Map <string, any> = new Map();
    map.set('fruit', 'orange');
    of(map).subscribe(
      (fruitsMap: Map<string, any>) => {
        console.log(fruitsMap);
      }
    );
  }

}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325053488&siteId=291194637