I found a very helpful article on stackoverflow:
AngularJS access parent scope from child controller
The solution provided access the parent's scope, when the parent controller is global.
So for:
(function() {
angular.module.controller('s').controller('ParentCtrl', function () {
var vm = this;
vm.cities = ["NY", "Amsterdam", "Barcelona"];
}
}());
(function() {
angular.module.controller('s').controller('ChildCtrl', function () {
var vm = this;
ParentCtrl.apply(vm, arguments);
vm.parentCitiesByScope = $scope.pc.cities;
vm.parentCities = vm.cities;
} }());
How can you access the ParentCtrl's cities attribute, if we place an IIFE for each controller? Notice this ParentCtrl is no longer in the same scope as the child controller, so that we can't call the apply function.
If I have the controllers in separate files, how can I access the scope of the parent?
While having this as the html:
<div ng-app ng-controller="ParentCtrl as pc">
<div ng-controller="ChildCtrl as cc">
<pre>{{cc.parentCities | json}}</pre>
<pre>{{pc.cities | json}}</pre>
</div>