Created
December 18, 2018 03:32
-
-
Save tedhagos/b5d2ceccb1898e9486a72129abd36d46 to your computer and use it in GitHub Desktop.
observable sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>{{ title }}</h1> | |
<button (click)="subscribe()"> | |
Subscribe | |
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { Observable, range } from 'rxjs'; | |
import {map, filter } from 'rxjs/operators' | |
import { ObserveOnMessage } from 'rxjs/internal/operators/observeOn'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'] | |
}) | |
export class AppComponent { | |
title = 'Observables'; | |
source$: Observable<number> = range(0,10); | |
mapfil$; | |
ngOnInit() { | |
console.log("on init"); | |
this.mapfil$ = this.source$.pipe( | |
map(x => x * x), | |
filter(x => x % 2 === 0) | |
); | |
console.log(typeof(this.mapfil$)); | |
} | |
subscribe() { | |
this.mapfil$.subscribe(x => console.log(x)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment