Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript, Angular - how to reload website after time

I have a problem. I'd like to reload website after 5 minutes and that is my question, how to reload website in Typescript/Angular application?

like image 414
akaoD Avatar asked Feb 26 '18 14:02

akaoD


People also ask

What is location reload ()?

The location. reload() method reloads the current URL, like the Refresh button.


1 Answers

In your main app component file, under ngOnInit(), you could add a setTimeout method that reloads every 5 minutes like so:

ngOnInit() {
  setTimeout(() => {
    window.location.reload();
  }, 300000); // Activate after 5 minutes.
}

Though I don't know your situation, I would highly advise against doing this. Most likely, whatever you are trying to accomplish, can probably be done in a better way than refreshing the page. That's just my opinion. For me as a User, i'd be really annoyed if i'm browsing a site and it just randomly refreshes.

like image 63
David Anthony Acosta Avatar answered Oct 09 '22 19:10

David Anthony Acosta