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 ="" }); }
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.
The function you are looking for is called setTimeout.
display(){ this.foodservice.getFood() .subscribe(data => { setTimeout(()=>{ this.display = "" }, 4000) } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With