Pradeep
Pradeep

Reputation: 4872

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

Upvotes: 0

Views: 621

Answers (1)

Thalaivar
Thalaivar

Reputation: 23632

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

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

Below is a simple fiddle showing it.

https://jsfiddle.net/2Lj26ru5/

Upvotes: 2

Related Questions