Skip to content

Instantly share code, notes, and snippets.

@splincode
Created September 1, 2019 14:46
Show Gist options
  • Select an option

  • Save splincode/da7a6f5508f6f57056e90ae70ccd3c14 to your computer and use it in GitHub Desktop.

Select an option

Save splincode/da7a6f5508f6f57056e90ae70ccd3c14 to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Component({
selector: 'my-app',
template: `
<p>
RxJS counter: {{ count$ | async }}
<button (click)="increment()">+</button>
<button (click)="decrement()">-</button>
</p>
`
})
export class AppComponent {
public count$: BehaviorSubject<number> = new BehaviorSubject(0);
public increment(): void {
this.count$.next( this.count$.getValue() + 1 );
}
public decrement(): void {
this.count$.next( this.count$.getValue() - 1 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment