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.

5
  • use setTimout() and call the ngOnInit() Commented Aug 19, 2017 at 7: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. Commented Aug 19, 2017 at 7: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. Commented Aug 19, 2017 at 7:34
  • Check out the answer to this question: stackoverflow.com/questions/35316583/… It goes into detail on how to set up a timer for this. Commented Aug 19, 2017 at 7:46
  • 1
    Possible duplicate of Angular2 http at an interval Commented Aug 19, 2017 at 8:25

2 Answers 2

2

try this

setTimeout( function(){ location.reload(); }, 10000); 
Sign up to request clarification or add additional context in comments.

Comments

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); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.