Michael Joshua Michael Joshua - 10 months ago 49
TypeScript Question

How to check if observable countdown timer has completed?

I have a simple countdown timer in angular 4

import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/timer';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/take';

counter = 60;
enableButton:boolean = false;

this.countDown = Observable.timer(0,1000).take(this.counter).map(() => --

I want to make enableButton boolean true when this observable has been completed.

How should I write that code? Please Help

Here is a plunker link, which I am using in my project

Answer Source

In the view:

    <button [disabled]="counter !== 0">OK</button>

and in the class:

  counter = 10;
  constructor() {

    this.countDown = Observable.timer(0,1000)
      .map(() => --this.counter)


and the plunker

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download