($injector: IInjectorService)
| 74 | */ |
| 75 | export function downgradeInjectable(token: any, downgradedModule: string = ''): Function { |
| 76 | const factory = function ($injector: IInjectorService) { |
| 77 | const injectorKey = `${INJECTOR_KEY}${downgradedModule}`; |
| 78 | const injectableName = isFunction(token) ? getTypeName(token) : String(token); |
| 79 | const attemptedAction = `instantiating injectable '${injectableName}'`; |
| 80 | |
| 81 | validateInjectionKey($injector, downgradedModule, injectorKey, attemptedAction); |
| 82 | |
| 83 | try { |
| 84 | const injector: Injector = $injector.get(injectorKey); |
| 85 | return injector.get(token); |
| 86 | } catch (err) { |
| 87 | throw new Error(`Error while ${attemptedAction}: ${(err as Error).message || err}`); |
| 88 | } |
| 89 | }; |
| 90 | (factory as any)['$inject'] = [$INJECTOR]; |
| 91 | |
| 92 | return factory; |
no test coverage detected
searching dependent graphs…