Angular 2: How to refresh entire page automatically on after some time
10,487
Solution 1
try this
setTimeout(
function(){
location.reload();
}, 10000);
Solution 2
you have two choices:
1- Using ng2-simple-timer-example:
Angular 2 has a simple component that handle timer: ng2-simple-timer-example
This plunker shows the result:
2- setTimout:
As @Araivnd mentions you can using ngOnInit(angular calls ngOnInit after creating the component) and setTimout as following:
ngOnInit(){
setTimeout(function(){
//code here
},10000);
}
Related videos on Youtube
Author by
PAR
Updated on June 04, 2022Comments
-
PAR almost 2 years
I am trying to code in Angular to such that it reloads entire HTML page automatically after 10 seconds.
Please help how to do it, i am new to Angular 2.
Thanks in advance.
-
Aravind over 6 yearsuse
setTimout()
and call thengOnInit()
-
DeborahK over 6 yearsCould you elaborate on the purpose for this? Do you want to reload the entire page? Or just the data for the page? The solution is different depending on which you require.
-
PAR over 6 years@Deorahk yes,In html page i am having calendar which contain events,once user clicked on that it ,it should block for 10 minutes and call the services again after 10 minutes and reload.
-
DeborahK over 6 yearsCheck out the answer to this question: stackoverflow.com/questions/35316583/… It goes into detail on how to set up a timer for this.
-
Rahul Singh over 6 yearsPossible duplicate of Angular2 http at an interval
-