angularjs源码笔记(3)--injector
程序员文章站
2024-01-13 16:53:16
...
简介
injector是用来做参数自动注入的,例如
functionfn ($http, $scope, aService) {
}
ng在运行时会把$http, $scope, aService 自动作为参数传入进行执行。
其实很容易想明白,injector做了两件事
- 缓存那些service,以后作为参数注入
- 分析参数列表,找到需要的参数注入
下面源码分析如何实现上面两件事情。
结构
createInjector -> createInternalInjector return: instanceInjector
所以 createInjector() 返回的是 instanceInjector,结构如下:
{
invoke: invoke,
instantiate: instantiate,
get: getService,
annotate: annotate,
has: function(name) {
return providerCache.hasOwnProperty(name + providerSuffix) || cache.hasOwnProperty(name);
}
}
省略.... 详细见 http://my.oschina.net/alexqdjay/blog/734434
上一篇: 基于RxTx的短信发送-长短信pdu
下一篇: ajax跨域