Arnold
Arnold

Reputation: 55

How to put time outs in angular2

I want to show a success message on firing submit button but only after 10 some sort of time and for that i wrote the following lines.

  let timeoutId = setTimeout(() => {  
                           this.success = true;;
                            },500);

Simmilarly,i want to close the message after certain amout of time ,let 5 sec .Can anyone suggest me how to do that.Thanks.

Upvotes: 0

Views: 48

Answers (2)

ranakrunal9
ranakrunal9

Reputation: 13558

Observable.timer(500).subscribe(() => {
  this.success = true;
  Observable.timer(5000).subscribe(() => this.success = false);
});

Upvotes: 1

Meir
Meir

Reputation: 14395

Observable.timer(500).subscribe(() => this.success = true)

Upvotes: 1

Related Questions