Skip to content

Commit 1ca93d0

Browse files
refactor(resolve): Defer building of resolves that require $injector.annotate (if $injector is not available, such as in ng1 during config phase)
Note: ng1 must then build those resolves at runtime, once $injector is available
1 parent 4fe39e3 commit 1ca93d0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/state/stateBuilder.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,13 @@ export function resolvablesBuilder(state: State): Resolvable[] {
151151
Object.keys(resolveObj || {}).map(token => ({token, val: resolveObj[token], deps: undefined, policy: resolvePolicies[token]}));
152152

153153
/** fetch DI annotations from a function or ng1-style array */
154-
const annotate = (fn: Function) =>
155-
fn['$inject'] || services.$injector.annotate(fn, services.$injector.strictDi);
154+
const annotate = (fn: Function) => {
155+
let $injector = services.$injector;
156+
// ng1 doesn't have an $injector until runtime.
157+
// If the $injector doesn't exist, use "deferred" literal as a
158+
// marker indicating they should be annotated when runtime starts
159+
return fn['$inject'] || ($injector && $injector.annotate(fn, $injector.strictDi)) || "deferred";
160+
};
156161

157162
/** true if the object has both `token` and `resolveFn`, and is probably a [[ResolveLiteral]] */
158163
const isResolveLiteral = (obj: any) => !!(obj.token && obj.resolveFn);

0 commit comments

Comments
 (0)