Angular parameter definition twice

Consider the following examples. Do they work differently?

.controller('MyController',function($scope) {
  $scope.username = 'World';

  $scope.sayHello = function() {
    $scope.greeting = 'Hello ' + $scope.username + '!';
  };
});

Vs

.controller('MyController', ['$scope', function($scope) {
  $scope.username = 'World';

  $scope.sayHello = function() {
    $scope.greeting = 'Hello ' + $scope.username + '!';
  };
}]);

They output the same for me, I just don’t understand why we posted it. Sometimes I have to use it as an object for work. Why define it twice?

+4
source share
1 answer

This is an interesting question. The answer is what works in the local environment. But..

, Minify/obfuscate JavaScript . $scope $s, $scope , Angular , $scope.

, -, , , !:)

: http://viralpatel.net/blogs/angularjs-controller-tutorial/

+6

Source: https://habr.com/ru/post/1625931/


All Articles