小编Tib*_* F.的帖子

AngularJS中的编码风格

虽然这个线程总结了以下三种代码样式:

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)因为它似乎是标准的做法吗?

coding-style angularjs

5
推荐指数
2
解决办法
214
查看次数

标签 统计

angularjs ×1

coding-style ×1