Reputation: 447
In angular if we define a controller then we write like
var app = angular.module('myMod',[]);
app.controller('myCtrl',function($scope){
})
Here $scope
is a DI, which is passed inside a callback function as an function argument. Now, I understand that naming matters in angular here, but apart from that what is really the difference between a Normal function argument and Dependency injection in angular.
Upvotes: 2
Views: 46
Reputation: 1774
You will notice that function($scope) {...} is the second argument to the .controller method of app. This is an anonymous function that gets executed when the controller is initialized. $scope is detected as a dependency by angular and passed into this controller function. Other than that, there isn't a difference. I generally don't think of the anonymous function as a function with arguments.
Another way to write that function is below. This is the more common manner to write as it will allow code minimizers to function properly. It tells angular what dependancies to inject in what order. The short circuit syntax you wrote also works.
var app = angular.module('myMod',[]);
app.controller('myCtrl', [ '$scope', function($scope){
}])
Upvotes: 0