From be55d9322e76e228c342560da9e20adc9b269064 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 12 May 2017 19:03:54 +0200 Subject: [PATCH] fix(router): Wrap Promise-like instances in native Promises (#16759) Hybrid apps (mix of Angular and AngularJS) might return AngularJS implementation of Promises that do not play well with the change detection. Wrapping them in native Promises fix this issue. This could be the case when a Resolver returns a `$q` promise. --- packages/router/src/utils/collection.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/router/src/utils/collection.ts b/packages/router/src/utils/collection.ts index c49a2daf8f43d..36ffcca7d89b4 100644 --- a/packages/router/src/utils/collection.ts +++ b/packages/router/src/utils/collection.ts @@ -97,7 +97,10 @@ export function wrapIntoObservable(value: T | NgModuleFactory| Promise| } if (isPromise(value)) { - return fromPromise(value); + // Use `Promise.resolve()` to wrap promise-like instances. + // Required ie when a Resolver returns a AngularJS `$q` promise to correctly trigger the + // change detection. + return fromPromise(Promise.resolve(value)); } return of (value);