2

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.

Jem Eripol
  • 225
  • 1
  • 13
PAR
  • 431
  • 1
  • 9
  • 21
  • use `setTimout()` and call the `ngOnInit()` – Aravind Aug 19 '17 at 07:19
  • 1
    Could 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. – DeborahK Aug 19 '17 at 07:24
  • @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. – PAR Aug 19 '17 at 07:34
  • Check out the answer to this question: https://stackoverflow.com/questions/35316583/angular2-http-at-an-interval It goes into detail on how to set up a timer for this. – DeborahK Aug 19 '17 at 07:46
  • 1
    Possible duplicate of [Angular2 http at an interval](https://stackoverflow.com/questions/35316583/angular2-http-at-an-interval) – Rahul Singh Aug 19 '17 at 08:25

2 Answers2

2

you have two choices:

1- Using ng2-simple-timer-example:

Angular 2 has a simple component that handle timer: ng2-simple-timer-example

Github Link

This plunker shows the result:

Online Plunker

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);
}
Iman Bahrampour
  • 6,180
  • 2
  • 41
  • 64
2

try this

setTimeout(
function(){ 
location.reload(); 
}, 10000);
Neji Soltani
  • 1,522
  • 4
  • 22
  • 41