如何延迟角度2

Lis*_*kor 20 angular

我试图在我的应用程序中设置显示延迟.运行程序后,消息显示正确,而不是仅显示4秒钟.这是我的延迟功能.可能有什么不对

 display(){    
      this.foodservice.getFood()
          .subscribe(data => 
          {
             delay (4000)
             this.display =""
          });
   }
Run Code Online (Sandbox Code Playgroud)

joe*_*4no 48

您正在寻找的功能称为setTimeout.

display(){

  this.foodservice.getFood(){
    .subscribe(data => {
      setTimeout(()=>{ this.display = "" }, 4000)
    }    
  }
}
Run Code Online (Sandbox Code Playgroud)