Book Image

AngularJS Web application development Cookbook

By : Matthew Frisbie
Book Image

AngularJS Web application development Cookbook

By: Matthew Frisbie

Overview of this book

Packed with easy-to-follow recipes, this practical guide will show you how to unleash the full might of the AngularJS framework. Skip straight to practical solutions and quick, functional answers to your problems without hand-holding or slogging through the basics. Avoid antipatterns and pitfalls, and squeeze the maximum amount out of the most powerful parts of the framework, from creating promise-driven applications to building an extensible event bus. Throughout, take advantage of a clear problem-solving approach that offers code samples and explanations of components you should be using in your production applications.
Table of Contents (17 chapters)
AngularJS Web Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using safe $apply


In the course of developing AngularJS applications, you will become very familiar with $apply() and its implications. The $apply() function cannot be invoked while the $apply() phase is already in progress without causing AngularJS to raise an exception. While in simpler applications, this problem can be solved by being careful and methodical about where you invoke $apply(); however, this becomes increasingly more difficult when applications incorporate third-party extensions with high DOM event density. The resulting problem is one where the necessity of invoking $apply is indeterminate.

As it is entirely possible to ascertain the state of the application when $apply() might need to be invoked, you can create a wrapper for $apply() to ascertain the state of the application, and conditionally invoke $apply() only when not in the $apply phase, essentially creating an idempotent $apply() method.

Tip

This recipe contains content that the AngularJS wiki considers an anti-pattern...