Created
September 1, 2019 14:46
-
-
Save splincode/da7a6f5508f6f57056e90ae70ccd3c14 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 } from '@angular/core'; | |
| import { BehaviorSubject } from 'rxjs'; | |
| @Component({ | |
| selector: 'my-app', | |
| template: ` | |
| <p> | |
| RxJS counter: {{ count$ | async }} | |
| <button (click)="increment()">+</button> | |
| <button (click)="decrement()">-</button> | |
| </p> | |
| ` | |
| }) | |
| export class AppComponent { | |
| public count$: BehaviorSubject<number> = new BehaviorSubject(0); | |
| public increment(): void { | |
| this.count$.next( this.count$.getValue() + 1 ); | |
| } | |
| public decrement(): void { | |
| this.count$.next( this.count$.getValue() - 1 ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment