0
<div ng-app="myApp" ng-controller="DoubleController" ng-init="content=50">
  <h1>{{double(50)}}</h1>
</div>

In the script part there are two styles.

myApp.controller('DoubleController', function ($scope) {
  $scope.double = function (value) {
    return value * 2;
  };
});

and

myApp.controller('DoubleController', ['$scope', function($scope) {
  $scope.double = function(value) { return value * 2; };

What is the difference between these two styles and what does $scope mean in ['$scope', function($scope){} ].

Thanks.

P.S.
  • 15,970
  • 14
  • 62
  • 86
Kunyuan Xiao
  • 175
  • 2
  • 13

1 Answers1

1

See Dependency Annotation at Angularjs docs. About the first style you show, it says:

Careful: If you plan to minify your code, your service names will get renamed and break your app.

So they recommend using the second style, since this won't break when minifying your code.

user125661
  • 1,558
  • 12
  • 28