How to get Angular controller and scope from an element using a jQuery selector

Michael Roma

The following shows how to get an Angular controller and it’s scope from an element using a jQuery selector. Here is an example Angular controller:

&ltdiv ng-controller=“ProfileSignupController”&gt
…
&lt/div&gt
To get the controller, use the following:
// get the controller by controller name
var controller = angular.element(“[ng-controller=‘” + name + “’]”);
Now since you have the controller, you now have access to the scope:
var scope = controller.scope();