fromEvent
signature: fromEvent(target: EventTargetLike, eventName: string, selector: function): Observable
fromEvent(target: EventTargetLike, eventName: string, selector: function): Observable
이벤트를 옵저버블로 전환해줍니다.
예시
예시 1: 마우스 클릭을 옵저버블로 전환
( StackBlitz | jsBin | jsFiddle )
// RxJS v6+
import { fromEvent } from 'rxjs';
import { map } from 'rxjs/operators';
// 클릭 이벤트를 내보내는 옵저버블을 생성합니다
const source = fromEvent(document, 'click');
//주어진 이벤트 타임스탬프를 사용하여 문자열에 맵핑합니다
const example = source.pipe(map(event => `Event time: ${event.timeStamp}`));
//결과 (예시): 'Event time: 7276.390000000001'
const subscribe = example.subscribe(val => console.log(val));
관련된 사용법
[Save Indicator]('../../recipes/save-indicator.md)
추가 자료
:newspaper: - 공식 문서
:file_folder: Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/fromEvent.ts
Last updated
Was this helpful?