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

Optimizing the application using equality $watch


Equality watches register a listener that uses angular.equals() as the comparator, which exhaustively examines the entirety of all objects to ensure that their respective object hierarchies are identical. Both a new object assignment and property modification will register as a change and invoke the watch callback.

This watcher should be used when any modification to an object is considered as a change event, such as a user object having its properties at various depths modified.

How to do it…

The equality comparator is used when the optional Boolean third argument is set to true. Other than that, these watchers are syntactically identical to reference comparator watchers, as shown here:

$scope.myObj = {
  myPrim: 'Go Bears!',
  myArr: [3,1,4,1,5,9]
};

// watch myObj by equality
$scope.$watch('myObj', function(newVal, oldVal, scope) {
  // callback logic
}, true);

How it works…

The equality comparator will invoke the watch callback on every modification...