( loader: () => Promise<InjectAsyncLoaderResult<T>>, options?: InjectAsyncOptions, )
| 56 | options?: InjectAsyncOptions, |
| 57 | ): () => Promise<T>; |
| 58 | export function injectAsync<T>( |
| 59 | loader: () => Promise<InjectAsyncLoaderResult<T>>, |
| 60 | options?: InjectAsyncOptions, |
| 61 | ): () => Promise<T> { |
| 62 | if (ngDevMode) { |
| 63 | assertInInjectionContext(injectAsync); |
| 64 | } |
| 65 | |
| 66 | const injector = inject(Injector); |
| 67 | const load = createLoader(loader); |
| 68 | |
| 69 | if (options?.prefetch) { |
| 70 | options |
| 71 | .prefetch() |
| 72 | .then(load) |
| 73 | .catch(() => {}); |
| 74 | } |
| 75 | |
| 76 | // We can't use `inject` later on because of the async nature of the loader |
| 77 | return () => load().then((loadedToken) => injector.get(maybeUnwrapDefaultExport(loadedToken))!); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Creates the memoized loader function in its own lexical scope so that the |
no test coverage detected