Skip to content

Instantly share code, notes, and snippets.

@tedhagos
Created December 18, 2018 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedhagos/b5d2ceccb1898e9486a72129abd36d46 to your computer and use it in GitHub Desktop.
Save tedhagos/b5d2ceccb1898e9486a72129abd36d46 to your computer and use it in GitHub Desktop.
observable sample
<h1>{{ title }}</h1>
<button (click)="subscribe()">
Subscribe
</button>
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