RxJS - Transformation Operator map



In the case of map operator, a project function is applied on each value on the source Observable and the same output is emitted as an Observable.

Syntax

map(project_func: function): Observable

Parameters

project_func − It takes in project_func as the argument which is applied to all the values of source observable.

Return value

An observable, with values as per the result of the project_func.

Example

import { fromEvent } from 'rxjs';
import { map } from 'rxjs/operators';
let btn = document.getElementById("btnclick");
let btn_clicks = fromEvent(btn, 'click');

let positions = btn_clicks.pipe(map(ev => ev));
positions.subscribe(x => console.log("x:"+x.clientX +" and y: "+x.clientY));

Output

map Operator
Advertisements