我正在尝试使用 conrollerAs 语法扩展控制器。我的父控制器和子控制器没有定义在同一个范围内,所以我把父控制器(BaseController
)放在一个服务中:
angular.module('myApp').factory('BaseController', function() {
var BaseController = function(fooService, barService) {
// base controller constructor logic
}
BaseController.prototype = {
// base controller methods
}
return BaseController;
});
然后像这样使用它:
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);
我ChildController
在ui路由器状态下使用。状态模板未加载,并且我在控制台中收到错误消息:
Resource for page controller is not defined <div class="ng-scope" ui-view="foo-view">
有任何想法吗?