本文介绍了AngularJS中的$ injector和Inject()之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
之间是否有任何区别/偏好:
Is there any difference/preference between:
inject(function($injector) {
rootScope = $injector.get('$rootScope');
});
还有
inject(function($rootScope){
rootScope = $rootScope;
});
在Jasmine中将资源注入测试中是否等于等价物?
Are the eqal as far as getting a resource injected into a test in Jasmine?
推荐答案
从文档注入功能:
因此,要回答您的问题,不,这两种方式确实没有区别,除了(我认为),使用inject函数获取依赖关系而不是通过$injector
So, to answer your question, no, there really isn't a difference in the two ways, other than (in my opinion) it's a lot easier to just use the inject function to get dependencies instead of going through the $injector
这篇关于AngularJS中的$ injector和Inject()之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!