Skip to content

Instantly share code, notes, and snippets.

@arturovt
Last active October 29, 2018 20:23
Show Gist options
  • Save arturovt/2aef3634a605f11eb6c89bcc468f92cc to your computer and use it in GitHub Desktop.
Save arturovt/2aef3634a605f11eb6c89bcc468f92cc to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { Select } from '@ngxs/store';
import { Emitter, Emittable } from '@ngxs-labs/emitter';
import { CounterState } from './counter.state';
@Component({
selector: 'app-counter',
template: `
<ng-container *ngIf="counter$ | async as counter">
<h3>Counter is {{ counter.value }}</h3>
<div>
<button (click)="increment.emit()">Increment</button>
<button (click)="decrement.emit()">Decrement</button>
</div>
</ng-container>
`
})
export class CounterComponent {
@Select(CounterState)
public counter$: Observable<number>;
@Emitter(CounterState.increment)
public increment: Emittable<void>;
@Emitter(CounterState.decrement)
public decrement: Emittable<void>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment