Search code examples
angularjsangularjs-scope

Angular Get Controller from Element


Is there a way to find the controller for an element through Chrome's console? I can get a reference to the component by selecting the element in the Elements Panel and using

var c = angular.element($0);

c has a controller property (looks like a constructor), but I'm not sure what to do with this. Is there any way to find the controller's name from here?


Solution

  • If you do angular.element($0).scope() or just $scope(if you installed Batarang Chrome extension), you should be able to get access to selected element's scope's functions and properties. This should also include any functions/attributes that a controller has exposed on the scope.

    There is no way to get the controller's name, though.