Created
March 21, 2019 08:27
-
-
Save takuya-nakayasu/251e21400e9b551c90923a6a54852c4b to your computer and use it in GitHub Desktop.
カウンターコンポーネントのコンポーネントクラス
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 } from '@angular/core'; | |
import { Observable } from 'rxjs'; | |
import { Store, select } from '@ngrx/store'; | |
import { Increment, Decrement, Reset } from '../action/counter.actions'; | |
@Component({ | |
selector: 'app-my-counter', | |
templateUrl: './my-counter.component.html' | |
}) | |
export class MyCounterComponent { | |
count$: Observable<number>; | |
constructor(private store: Store<{ count: number }>) { | |
this.count$ = store.pipe(select('count')); | |
} | |
increment() { | |
this.store.dispatch(new Increment()); | |
} | |
decrement() { | |
this.store.dispatch(new Decrement()); | |
} | |
reset() { | |
this.store.dispatch(new Reset()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment