Created
January 14, 2016 18:07
-
-
Save qdouble/79c4ba4339b93c78bb69 to your computer and use it in GitHub Desktop.
counter test
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, ViewChild, ViewChildren} from 'angular2/core'; | |
import {Observable} from 'rxjs/Observable'; | |
import {Store} from '@ngrx/store'; | |
import {INCREMENT, DECREMENT, RESET} from './../../../counter'; | |
@Component({ | |
selector: 'my-app', | |
template: ` | |
<button (click)="increment()">Increment</button> | |
<div>Current Count: {{ counter | async }}</div> | |
<button (click)="decrement()">Decrement</button> | |
<br/> | |
<button (click)="increment2()">Increment</button> | |
<div>Current Count: {{ counter2 | async }}</div> | |
<button (click)="decrement2()">Decrement</button> | |
` | |
}) | |
export class MyStore { | |
counter: Observable<number>; | |
counter2: Observable<number>; | |
constructor(public store: Store<any>, public store2: Store<any>){ | |
this.counter = store.select('counter'); | |
this.counter2 = store2.select('counter2'); | |
} | |
increment(){ | |
this.store.dispatch({ type: INCREMENT }); | |
} | |
decrement(){ | |
this.store.dispatch({ type: DECREMENT }); | |
} | |
reset(){ | |
this.store.dispatch({ type: RESET }); | |
} | |
increment2(){ | |
this.store2.dispatch({ type: INCREMENT }); | |
} | |
decrement2(){ | |
this.store2.dispatch({ type: DECREMENT }); | |
} | |
reset2(){ | |
this.store2.dispatch({ type: RESET }); | |
} | |
ngOnDestroy() { | |
this.reset(); | |
this.reset2(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment