Pradeep Pradeep - 1 year ago 91
AngularJS Question

Access $scope variable of ng-include in parent $scope

I have created an angular application where my views are loading in ng-view tag based on the route configuration. In once of my view I am loading sub templates using ng-include based on a dropdown selection dynamically. On button click action on the main view I want to get the scope of the view which is loaded in ng-include. Can anybody suggest me how to do it ?

enter image description here

Answer Source

You could do something like this to access a particular controller scope.

var ctrlElement = document.querySelector('div');
var ctrlScope = angular.element(ctrlElement).scope();

Below is a simple fiddle showing it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download