angular provider 注入
1 | angularModule('ng', ['ngLocale'], ['$provide', |
注意 ['$provide',function ngModule($provide){}]
这段代码,
在定义angular.module方法时 就加入了configFn参数:
1 | * @param {Function=} configFn Optional configuration function for the module. Same as |
configBlocks push了[‘$injector’,’invoke’,[‘$provide’,function($provide){}]]
然后在bootstrap方法中createInjector
createInjector中再调用loadModules
loadModules中runInvokeQueue(moduleFn._configBlocks);
调用providerCache.$injector 返回
{
invoke: invoke,
instantiate: instantiate,
get: getService,
annotate: createInjector.$$annotate,
has: function(name) {
return providerCache.hasOwnProperty(name + providerSuffix) || cache.hasOwnProperty(name);
}
}
继续调用invoke函数 -> injectionArgs -> getService(key) 返回$provide 对象