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

Sun Jun 21 2015

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:

<div ng-controller="ProfileSignupController">
...
</div>

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();