Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between these two angularjs controller definition

I don't understand the difference between these two types of angularjs controller definition, i have tried following codes and found both working

myApp.controller('GreetingController', ['$scope', function($scope) {
  $scope.greeting = 'Hola!';
}]);

myApp.controller('GreetingController', function($scope) {
  $scope.greeting = 'Hola!';
});
like image 281
Bamaboy Avatar asked May 12 '26 23:05

Bamaboy


1 Answers

First one cares about minification.

In this controller:

myApp.controller('GreetingController', function($scope) {
    $scope.greeting = 'Hola!';
});

arguments will be minimized to some short values and dependency injection will not work.

Please look at:

  • https://docs.angularjs.org/guide/di#dependency-annotation
  • https://docs.angularjs.org/tutorial/step_05
  • What are the differences in angular controller notation?
like image 162
kTT Avatar answered May 15 '26 12:05

kTT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!