1

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. });

2
  • You could help us a lot by including the part of Angular's source code that you'd like to get explained in your question. Would you mind to edit? Commented Oct 5, 2014 at 21:17
  • Could you mark answer if you feel the answer was satisfactory? Commented Oct 27, 2014 at 19:16

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thats a big read @Snowman and looks promising on the first glance will give it a complete read...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.