I'm trying to extend controllers using conrollerAs syntax.
My parent and child controllers are not defined in the same scope, so I put the parent controller (BaseController
) in a service:
angular.module('myApp').factory('BaseController', function() {
var BaseController = function(fooService, barService) {
// base controller constructor logic
}
BaseController.prototype = {
// base controller methods
}
return BaseController;
});
Then use it like so:
var ChildController = function(BaseController, fooService, barService) {
BaseController.apply(this, [fooService, barService]);
}
var BaseController = angular.injector(['myApp']).get('BaseController');
ChildController.prototype = Object.create(angular.extend(BaseController.prototype, {
fooMethod: function() {
// do stuff
}
}));
angular.module('myApp').controller('ChildController', ChildController);
I use ChildController
in a ui router state. The state template doesn't load, and I get an error in the console:
Resource for page controller is not defined <div class="ng-scope" ui-view="foo-view">
Any ideas?