Reputation: 10827
I have learned in past about AngularJS dependency injection and it does it by calling the toString on the controller and then parsing the arguments and then calling the function with dependent arguments i.e $scope, $http, $location and so on..
I've searched for the implementation of this and didnot find any understandable or actual smaller implementation to this.
So if someone can explain this using a very simple implementation(pure JS) that would be helpful for all
app.controller("MainCtrl", function($scope) {
//Here the $scope is dependency injected and would'nt work if some another variable name was used.
});
Upvotes: 1
Views: 1374
Reputation: 5736
This one is a general javascript implementation linked in the top of the angular specific one below. Both are good reads though.
http://teropa.info/blog/2014/06/04/angularjs-dependency-injection-from-the-inside-out.html
Upvotes: 3