Want to access parent property using Controller As notation? Since your using the “controller as” notation, witin your ChildCtrl you can access the MainCtrl using $scope.main, for example $scope.main.name.
1 2 3 4 5 6 7 8 9 10 11 | var app = angular.module('app', []); app.controller('MainCtrl', function($scope) { this.name = 'Main'; this.test = {}; }); app.controller('ChildCtrl', function($scope) { this.name = 'Child'; alert($scope.main.name); }); |
1 2 3 4 5 6 7 8 9 10 11 | <html ng-app="app"> <script src="https://ajax.googleapis.com/ajax/libs/ angularjs/1.2.23/angular.min.js"></script> <body ng-controller="MainCtrl as main"> <div ng-controller="ChildCtrl as child"> {{ main.name }} + {{ child.name }} </div> </body> </html> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.