Created
September 1, 2019 19:21
-
-
Save splincode/d2e7606e6e177ca25e49a43c12d36e67 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 { Store, select } from '@ngrx/store'; | |
import { Observable } from 'rxjs'; | |
import { ActionTypes } from './store/actions/counter'; | |
@Component({ | |
selector: 'my-app', | |
template: ` | |
<p> | |
NgRx Count: {{ count$ | async }} | |
<button (click)="increment()">+</button> | |
<button (click)="decrement()">-</button> | |
</p> | |
` | |
}) | |
export class AppComponent { | |
public count$: Observable<number> = this.store.pipe(select('count')); | |
constructor(private store: Store<{ count: number }>) { } | |
public increment(): void { | |
this.store.dispatch({ type: ActionTypes.Increment }); | |
} | |
public decrement(): void { | |
this.store.dispatch({ type: ActionTypes.Decrement }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment