The form of the inline Array annotation is:
somemodule. ( ' Mycontroller ' , [ ' $scope ' , ' greeter ' Span class= "pun" >, function ( $scope , Greeter) { //... }]);
where function ($scope, greeter) {} represents the $scope object, respectively, Greeter object.
Now I'm going to change the code above:
someModule.controller(‘MyController‘, [‘$scope‘, ‘greeter‘, function(a,b) { // ...}]);
其中参数a代表的是$scope对象,参数b代表的是greeter对象,至于我们在开发时把参数和和参数所代表的对象取相同的名字是为了见名知义。
下面的代码是参数的名字和对象名字不一致的情况:
<! DOCTYPE html>"en">"UTF-8"> <title>Title</title>".. /materialdesignfile/angular.js"></script> <script>Angular.module ('myApp', []). Factory ('MyService', function () {varfactory={}; Factory.name="Ouyangfeng"; Factory.sayhello=function () {Debugger Console.log ("Say hello"); } returnFactory; })
Sixi represents the object that $scope,ouyangfeng represents: MyService. . Controller ('Myctrl',['$scope','MyService', Function (Sixi,ouyangfeng) {Sixi.sixi="Si Xi"; Debugger Sixi.hello=Ouyangfeng.sayhello; Sixi.name=Ouyangfeng.name; }]); </script> <div ng-app="myApp"Ng-controller="Myctrl"> "Hello ()">hello</button>
Angular JS's inline Array annotation understanding