Posted in: Angular

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

Posted on June 22, 2015 by 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:

<div ng-controller="ProfileSignupController">

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