startWith

signature: startWith(an: Values): Observable

주어진 값을 처음으로 방출합니다.

💡 BehaviorSubject 또한 초기값부터 시작할 수 있습니다!

예시

( 예시 테스트 )

예시 1: 연속된 숫자와 startWith 사용하기

( StackBlitz | jsBin | jsFiddle )

// RxJS v6+
import { startWith } from 'rxjs/operators';
import { of } from 'rxjs';

//방출 (1,2,3)
const source = of(1, 2, 3);
// 0부터 시작
const example = source.pipe(startWith(0));
//결과: 0,1,2,3
const subscribe = example.subscribe(val => console.log(val));

예시 2: scan한 값과 startWith사용하기

( StackBlitz | | jsBin | jsFiddle )

예시 3: 복수의 값들을 startWith로 사용하기

( StackBlitz | jsBin | jsFiddle )

관련한 사용법

추가 자료

📂 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/startWith.ts

Last updated

Was this helpful?