Liska Liskor
Liska Liskor

Reputation: 2991

How to make a delay in angular 2

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 =""
          });
   }

Upvotes: 33

Views: 101302

Answers (1)

joed4no
joed4no

Reputation: 1363

The function you are looking for is called setTimeout.

display(){
  this.foodservice.getFood()
    .subscribe(data => {
      setTimeout(()=>{ this.display = "" }, 4000)
    }    

}

Upvotes: 78

Related Questions