Below are two different implementations of a controller in Angularjs. In the first type the author wrapped the controller function within square braces and defined two parameters before the function and passed them into the function(like array).
myapp.controller('axajCtrl',['$http','$scope',function($http,$scope){
$http.get('extras/data.json').success(function(response){ //make a get request to mock json file.
$scope.data = response; //Assign data received to $scope.data
})
.error(function(err){
//handle error
})
}])
In the second type after the controller name there is a function that implements the controller functionality.
myapp.controller('axajCtrl',function($http,$scope){
$http.get('extras/data.json').success(function(response){ //make a get request to mock json file.
$scope.data = response; //Assign data received to $scope.data
})
.error(function(err){
//handle error
})
});
I am confused with the first type of implementation. Why is the function defined like an array. Does the first implementation have any advantages over second one?