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

Inspecting your application's watchers


The Batarang browser plugin allows you to inspect the application's watch tree, but there are many scenarios where dynamically inspecting the watch list within the console or application code can be more helpful when debugging or making design decisions.

How to do it…

The following function can be used to inspect all or part of the DOM for watchers. It accepts an optional DOM element as an argument.

var getWatchers = function (element) {
  // convert to a jqLite/jQuery element
  // angular.element is idempotent
  var el = angular.element(
      // defaults to the body element
      element || document.getElementsByTagName('body')
    )
    // extract the DOM element data
    , elData = el.data()
    // initalize returned watchers array
    , watchers = [];

  // AngularJS lists watches in 3 categories
  // each contains an independent watch list
  angular.forEach([
      // general inherited scope
      elData.$scope,
      // isolate scope attached to...