Skip to content

Instantly share code, notes, and snippets.

@yjaaidi
Last active May 30, 2018 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yjaaidi/34e3643e321f93318bb27d3655b5aebd to your computer and use it in GitHub Desktop.
Save yjaaidi/34e3643e321f93318bb27d3655b5aebd to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { Subscription, interval } from 'rxjs';
@Component({
template: `<div>{{ count }}</div>`
})
export class CounterComponent implements OnDestroy, OnInit {
count: number;
private _countSubscription: Subscription;
ngOnInit() {
this._countSubscription = interval(1000)
.subscribe(count => this.count = count);
}
ngOnDestroy() {
if (this._countSubscription != null) {
this._countSubscription.unsubscribe();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment