0
我一直在開發一些角度控制器,我一直在提出一個我不太喜歡的模式。鑑於以下幾點:AngularJS中的Init方法?
app.controller('RecordCtrl', ['$scope', function AppBuilderCtrl($scope) {
// do lots of object initing here ...
$scope.model = { ... };
$scope.defs = $scope.buildDefs($scope.model);
// lots of functions on scope ...
$scope.defs = function(model) { ... };
});
的defs
拋出未定義(杜它不是直到之後定義),但是我最終感動了很多我的初始化代碼,這似乎不是很大的底部。我想我可以做這樣的事情:
// top of controller
init = function(){ ... }
// all my methods here
init();
但這也是呃。有什麼想法嗎?
我看到...我下的印象,服務被更多用於AJAX請求和輔助方法的模型從返回。 – amcdnl
@amcdnl是的,他們也用於此,但不是唯一的。 「角度服務是單個對象或功能,執行Web應用程序通用的特定任務。」根據http://docs.angularjs.org/guide/dev_guide.services.understanding_services – m59