1

I have started going through the Angular docs and wondered what is the difference between this controller constructor:

angular.module('myApp', [])
    .controller('SomeController', function() {
      this.qty = 1;
}); 

And this one:

angular.module('myApp', [])
    .controller('SomeController', ['$scope', function($scope) {
       $scope.qty = 1;
}]); 

Which of the two is preferred and why?
What is the added value of the injected $scope object?

0

1 Answer 1

2

When you are trying to minify the code, at that time

angular.module('myApp', [])
    .controller('SomeController', ['$scope', function($scope) {
       $scope.qty = 1;
}]); 

Would be useful to inject the dependencies properly.

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

2 Comments

Thanks, but this doesn't answer $scope vs this; it only explains why to declare '$scope' explicitly as a dependency in the array. I'm already checking it out; thanks for help anyway.
How does this address the question of whether $scope or this should be used?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.