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.

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.