简体   繁体   English

AngularJS控制器的构造函数声明意义

[英]AngularJS Controller's constructor function declaration significance

I am new to AngularJs. 我是AngularJs的新手。 While learning ,i am seeing these two types of controller declarations. 在学习的同时,我看到了这两种类型的控制器声明。

Can you guys just tell me the significance of each type mentioned below. 你们能告诉我下面提到的每种类型的重要性吗?

Type 1: 类型1:

var myApp = angular.module('myApp',[]);
myApp.controller('DoubleController', ['$scope', function($scope) {
$scope.letter="A";
}]);

Type 2: 类型2:

var myApp = angular.module('myApp',[]);
myApp.controller('DoubleController', [ function($scope) {
$scope.letter="A";
}]);

In the first type (recommended type), the string "$scope" is used for minification purposes - all arguments are shortend to one or two characters. 在第一种类型(推荐类型)中,字符串"$scope"用于缩小目的-所有参数都缩短为一个或两个字符。 Strings are not minified, therefore Angular will use this string when injecting to the controller. 字符串不是最小的,因此,Angular在注入控制器时将使用此字符串。 Look at this reference: https://stackoverflow.com/a/18782380/5954939 查看此参考资料: https : //stackoverflow.com/a/18782380/5954939

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM