一 ;书上是这样写控制的:
var myApp = angular.module('MyApp', []);
myApp.controller('MyController', function($scope){
})
二 平时是这样写的:
var myApp = angular.module('MyApp', []);
myApp.controller('MyController', ['$scope', function($scope){
}]);
那么问题来了,后者加了个
[]
,是个什么意思?这两种写法有什么不同呢?
这种写法的主要目的是
为了避免后期源码压缩时变量名被替换,导致依赖注入失败的问题。