Browser Events

There are several events that are triggered by the browser itself. In a way these are also user-interaction events; however, I want to keep them separate for this discussion. The browser events include things like the ready event when the document is loaded, as well as the resize event when the browser is resized.

These are useful to know when the view of the user is changing. You have already seen how to use the .on() function to add handlers for events; the question is where to put the handler. The best solutions I’ve seen involve a handler that is registered in the run block for the entire application. Any information can then be made available to subsequent components through the scope model or through a cache service.

Get Learning AngularJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.