简体   繁体   English

逆向工程AngularJS依赖注入

[英]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.. 我过去了解过AngularJS依赖注入,它是通过在控制器上调用toString然后解析参数,然后调用带有依赖参数(即$ scope,$ http,$ location等)的函数来实现的。

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 因此,如果有人可以使用非常简单的实现(纯JS)解释这一点,那么对所有人

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. 是一个通用的javascript实现,链接在下面的特定角度的顶部。 Both are good reads though. 两者都是不错的读物。

http://teropa.info/blog/2014/06/04/angularjs-dependency-injection-from-the-inside-out.html http://teropa.info/blog/2014/06/04/angularjs-dependency-injection-from-the-inside-out.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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