Skip to content

Instantly share code, notes, and snippets.

@splincode
Created September 1, 2019 19:21
Show Gist options
  • Save splincode/d2e7606e6e177ca25e49a43c12d36e67 to your computer and use it in GitHub Desktop.
Save splincode/d2e7606e6e177ca25e49a43c12d36e67 to your computer and use it in GitHub Desktop.
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