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?
source
share