Pradeep Pradeep - 11 months ago 59
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.