角度范围,范围?

时间:2014-10-09 13:51:09

标签: angularjs angularjs-scope

我正在学习Angular,当他们问为什么$ scope通过两次时,他正在向同事解释控制器

['$scope', function($scope) {

任何人都可以启发我们吗?

 myApp.controller('appList', ['$scope', function($scope) {
        $scope.things = [
            {
                "name":"Cheese",
                "id":"1",
                "short-name":"ch"
            },
            {
                "name":"Bread",
                "id":"2",
                "short-name":"br"
            },
            {
                "name":"Wine",
                "id":"3",
                "short-name":"wi"
            }
        ];
    }]);

我们所写的这个例子过于简单。

1 个答案:

答案 0 :(得分:1)

您不必传递数组。它与缩小有关,它在AngularJS tutorial中注明,当您缩小这样的代码时

['$scope', function($scope) {

minifyer会尽最大努力重命名以使代码尽可能小,包括参数,因此您的代码行最终会像这样结束

['$scope',function(a){

现在$scope参数已重命名,但AngularJS仍然知道您希望注入名称为$scope的内容,而不是a。如果您不自己制作此列表并缩小代码,AngularJS无法读取函数参数列表,也不会知道将哪些内容注入您的(在您的示例中)控制器中。

tool that automate this listing,您可以将这些与您可能正在使用的任何构建工具集成在一起,以自动化将依赖关系列为字符串的整个过程,并将其缩小。

相关问题