I'm trying to follow John Papa's guidelines, in which he explains how using this combined with controllerAs is preferable to $scope.
The problem is that I can't find an easy way to get a variable (user) defined in ParentController (vm.user) and use it, even transform it in a ChildController.
Code for illustration :
controllers.js
app.controller('ParentController', function() {
var vm = this;
vm.user = {firstName:"John", lastName:"doe"};
});
app.controller('ChildController', function() {
var vm = this;
/* How can I access 'vm.user' defined in ParentController
without using $scope as John Papa's suggests ? */
});
index.html
<div ng-controller="ParentController as parent">
<div ng-controller="ChildController as child">
</div>
I could just put everything in one big controller but I want to keep my code clean and readable.
Thanks!