Skip to content

Instantly share code, notes, and snippets.

@splincode
Last active August 31, 2019 19:08
Show Gist options
  • Save splincode/6ae1ec4d896c56bb9643f8bfa0188cd7 to your computer and use it in GitHub Desktop.
Save splincode/6ae1ec4d896c56bb9643f8bfa0188cd7 to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { Store, Select } from '@ngxs/store';
import { Observable } from 'rxjs';
import { Dispatch } from '@ngxs-labs/dispatch-decorator'
import { CountState } from './store/counter/count.state';
import { Increment, Decrement } from './store/counter/count.actions';
@Component({
selector: 'my-app',
template: `
<p>
NGXS counter: {{ count$ | async }}
<button (click)="increment()">+</button>
<button (click)="decrement()">-</button>
</p>
`
})
export class AppComponent {
@Select(CountState) count$: Observable<number>;
@Dispatch() public increment = () => new Increment();
@Dispatch() public decrement = () => new Decrement();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment