/**
* Converts a `SingleProvider` into a factory function.
*
* @param {?} provider provider to convert to factory
* @param {?=} ngModuleType
* @param {?=} providers
* @return {?}
*/
function providerToFactory(provider, ngModuleType, providers) {
/** @type {?} */
let factory = undefined;
if (isTypeProvider(provider)) {
/** @type {?} */
const unwrappedProvider = resolveForwardRef(provider);
return getFactoryDef(unwrappedProvider) || injectableDefOrInjectorDefFactory(unwrappedProvider);
}
else {
if (isValueProvider(provider)) {
factory = (/**
* @return {?}
*/
() => resolveForwardRef(provider.useValue));
}
else if (isFactoryProvider(provider)) {
factory = (/**
* @return {?}
*/
() => provider.useFactory(...injectArgs(provider.deps || [])));
}
else if (isExistingProvider(provider)) {
factory = (/**
* @return {?}
*/
() => ɵɵinject(resolveForwardRef(provider.useExisting)));
}
else {
/** @type {?} */
const classRef = resolveForwardRef(provider &&
(((/** @type {?} */ (provider))).useClass || provider.provide));
if (!classRef) {
throwInvalidProviderError(ngModuleType, providers, provider);
}
if (hasDeps(provider)) {
factory = (/**
* @return {?}
*/
() => new (classRef)(...injectArgs(provider.deps)));
}
else {
return getFactoryDef(classRef) || injectableDefOrInjectorDefFactory(classRef);
}
}
}
return factory;
}UseValue和UseExisting可以在此处打断点调试: