inline Array annotation的形式是:
someModule.controller('MyController', ['$scope', 'greeter', function($scope, greeter) {
// ...
}]);
其中function($scope,greeter){}分别代表$scope对象,greeter对象。
现在我把上面的代码改动一点:
someModule.controller('MyController', ['$scope', 'greeter', function(a,b) {
// ...
}]);
其中参数a代表的是$scope对象,参数b代表的是greeter对象,至于我们在开发时把参数和和参数所代表的对象取相同的名字是为了见名知义。
下面的代码是参数的名字和对象名字不一致的情况:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script src="../materialDesignfile/angular.js"></script>
<script>
angular.module('myApp',[])
.factory('myService',function () {
var factory={};
factory.name="ouyangfeng";
factory.sayHello=function () {
debugger
console.log("say hello");
}
return factory;
})
//sixi代表的对象是$scope,ouyangfeng代表的对象是:myService.
.controller('myCtrl',['$scope','myService',function (sixi,ouyangfeng) { sixi.sixi="泗溪";
debugger
sixi.hello=ouyangfeng.sayHello;
sixi.name=ouyangfeng.name;
}]);
</script>
<div ng-app="myApp" ng-controller="myCtrl">
<h1>{{sixi}}</h1>
<button ng-click="hello()">hello</button>
<h1>{{name}}</h1>
</div>
</body>
</html>