虽然这个线程总结了以下三种代码样式:
1)
angular.module('mainCtrl', []);
function MainCrl($scope, $rootScope) {}
Run Code Online (Sandbox Code Playgroud)
2)
angular.module('mainCtrl',[])
.controller('MainCtrl', function($scope, $rootScope)) { ... });
Run Code Online (Sandbox Code Playgroud)
3)
angular.module('mainCtrl',[])
.controller('MainCtrl', ['$scope', '$rootScope', function(scope, rootScope)) { ... }]);
Run Code Online (Sandbox Code Playgroud)
我在这个视频中看到的第四种方式对我很有吸引力
4)
var controllers = {}
controllers.mainCtrl = function($scope, $rootScope){ };
app.controller(controllers)
Run Code Online (Sandbox Code Playgroud)
我倾向于继续4),如果缩小它会破裂还是有任何其他缺点?我应该选择3)因为它似乎是标准的做法吗?