1. 程式人生 > >RxJS之組合操作符 ( Angular環境 )

RxJS之組合操作符 ( Angular環境 )

width one XP log obs ons core con color

一 merge操作符

把多個 Observables 的值混合到一個 Observable 中

import { Component, OnInit } from ‘@angular/core‘;
import { of } from ‘rxjs/observable/of‘;
import { range } from ‘rxjs/observable/range‘;
import { merge } from ‘rxjs/observable/merge‘;
import { Observable } from ‘rxjs/Observable‘;

@Component({
  selector: ‘app-combine‘
, templateUrl: ‘./combine.component.html‘, styleUrls: [‘./combine.component.css‘] }) export class CombineComponent implements OnInit { constructor() { } ngOnInit() { const low: Observable<number> = range(100, 3); const middle: Observable<number> = range(200, 3); const high: Observable
<number> = range(300, 3); merge(low, middle, high).subscribe((val: number) => { console.log(val); }); } }

技術分享圖片

RxJS之組合操作符 ( Angular環境 )