【发布时间】:2013-12-23 20:34:39
【问题描述】:
我正在使用 Angular 来构建一个大型应用程序,并且我有一些常用的控制器方法,实际上我正在这样做,但存在最好的方法吗?
app.controller('baseController', function($scope, $controller, appFactory) {
var $scope.foo = function() {
// Do something
}
});
app.controller('childController', function($scope, $controller, appFactory) {
// Here i extend or something like, the base controller
$controller('baseController', {$scope: $scope});
var $scope.bar = function() {
// Do a lot of things an then call foo
$scope.foo();
}
}):
我这样做是因为这些方法需要我的控制器的 $scope。
【问题讨论】:
-
一般常用的方法应该进入提供者(服务,工厂,...)。请记住,Angular 是围绕“在视图和模型之间进行调解”的瘦控制器设计的。如果您能提供更多细节,我可能会给您更具体的建议
标签: javascript angularjs