简体   繁体   中英

Reverse Engineering AngularJS dependency Injection

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM