Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a delay in angular 2

Tags:

angular

I am trying to set a delay for a display in my app. After I run the program, the message is displayed correctly and stays instead of displaying for just 4 seconds. This my delay function. What could be wrong

 display(){           this.foodservice.getFood()           .subscribe(data =>            {              delay (4000)              this.display =""           });    } 
like image 205
Liska Liskor Avatar asked Jan 26 '17 23:01

Liska Liskor


People also ask

What is delay in angular?

Delay & DelayWhen Operators in Angular delays the emission of values from the source observable. The Delay operator delays by a given timeout or until a given Date. The DelayWhen delays until it receives a notification from another observable.


1 Answers

The function you are looking for is called setTimeout.

display(){   this.foodservice.getFood()     .subscribe(data => {       setTimeout(()=>{ this.display = "" }, 4000)     }      } 
like image 178
joed4no Avatar answered Sep 23 '22 06:09

joed4no