0

Is there any way with AngularJS to force a page to refresh after it has been changed. What I mean by this is that I have multiple users actively working in the app but a change is required to the controller.js file. At this point the only way I'm aware of is for them to manually push refresh on the browser. Is there any code that I can use to make it "actively" watch that file for changes and reload when necessary without the users having to manually push refresh?

  • You can use ajax and refresh only the content, or use normal Javascript to reload the page, such as location.reload(); – Mr.Web Jan 06 '16 at 17:21

2 Answers2

1

This isn't really an angular problem. You can do polling on the client side with setInterval, hitting the file on the server to trigger a refresh on the client.

httpete
  • 2,765
  • 26
  • 34
  • I would also recommend a recursive setTimeout instead of setInterval, in case that your response is slower than the interval. http://stackoverflow.com/questions/23178015/recursive-function-vs-setinterval-vs-settimeout-javascript – httpete Jan 06 '16 at 17:39
  • I appreciate the quick response. I have not lost sight of this but just haven't had a chance to try and implement yet. Will get back as soon as possible. Your response does seem to be along the lines of what I'm looking for though! – Jason Olson Jan 20 '16 at 20:51
0

If you're looking for something to speed up development, then you're probably looking for hot module loading. The solution depends on what version of angular and build tool you're using (e.g. grunt/webpack/npm).

Check out this article for angular 2, but you can find similar solutions for angular 1: http://blog.mgechev.com/2015/10/26/angular2-hot-loader-hot-loading-tooling/

But if you just want to force a page refresh from the client side, you would just call: $window.location.reload()

michael salmon
  • 398
  • 4
  • 12