I have a pretty big question about this issue but I thought it might be easy to split it in smaller ones.
So, I'm trying to use $controller to inherit from a ParentController, but things are not working as expected.
I have a jsfiddle here. And this is the code.
angular
.module("app",[])
.controller('ParentController', ParentController)
.controller('ChildController', ChildController)
ParentController.$inject = ['$scope']
ChildController.$inject = ['$controller', '$scope'];
function ParentController($scope) {
var vm = this;
vm.foo = 'parent foo';
}
function ChildController($controller, $scope) {
$controller('ParentController as vm', {$scope: $scope});
var vm = $scope.vm; // view model
}
And a simple html
<div>
{{vm.foo}}
</div>
When I configure the app to use the ParentController, with this
<body ng-app="app" ng-controller="ParentController as vm">
it works fine.
But as it is now, with the ChildController, is not working, it's like vm does not include the property foo created in ParentController.
What am I doing wrong?
Many thanks.
