RxJS - Transformation Operator mapTo



A constant value is given as output along with the Observable every time the source Observable emits a value.

Syntax

mapTo(value: any): Observable

Parameters

value − It takes in the value as an argument and this value will be a map to the source value given.

Return value

It returns an Observable with values emitted when source observable emits.

Example

import { fromEvent } from 'rxjs';
import { mapTo } from 'rxjs/operators';

let btn = document.getElementById("btnclick");
let btn_clicks = fromEvent(btn, 'click');
let positions = btn_clicks.pipe(mapTo ("Testing MapTo"));
positions.subscribe(x => console.log(x));

Output

mapTo Operator
Advertisements