From 2af58622c1789673a527125e059af4c553598a26 Mon Sep 17 00:00:00 2001 From: Dzmitry Shylovich Date: Thu, 19 Jan 2017 02:56:34 +0300 Subject: [PATCH] fix(router): enable loadChildren with function in aot (#13909) Closes #11075 --- modules/@angular/router/src/config.ts | 5 +++-- modules/@angular/router/src/utils/collection.ts | 6 ++++-- tools/public_api_guard/router/index.d.ts | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/@angular/router/src/config.ts b/modules/@angular/router/src/config.ts index e4c7a781750d9..dc68e60cedf55 100644 --- a/modules/@angular/router/src/config.ts +++ b/modules/@angular/router/src/config.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Type} from '@angular/core'; +import {NgModuleFactory, Type} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {PRIMARY_OUTLET} from './shared'; import {UrlSegment, UrlSegmentGroup} from './url_tree'; @@ -310,7 +310,8 @@ export type ResolveData = { * See {@link Routes} for more details. * @stable */ -export type LoadChildrenCallback = () => Type| Promise>| Observable>; +export type LoadChildrenCallback = () => + Type| NgModuleFactory| Promise>| Observable>; /** * @whatItDoes The type of `loadChildren`. diff --git a/modules/@angular/router/src/utils/collection.ts b/modules/@angular/router/src/utils/collection.ts index 5046aefd71f1e..4bafad0cf4dd5 100644 --- a/modules/@angular/router/src/utils/collection.ts +++ b/modules/@angular/router/src/utils/collection.ts @@ -6,6 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ +import {NgModuleFactory} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {fromPromise} from 'rxjs/observable/fromPromise'; import {of } from 'rxjs/observable/of'; @@ -126,7 +127,8 @@ export function andObservables(observables: Observable>): Observ return every.call(merged$, (result: any) => result === true); } -export function wrapIntoObservable(value: T | Promise| Observable): Observable { +export function wrapIntoObservable(value: T | NgModuleFactory| Promise| Observable): + Observable { if (value instanceof Observable) { return value; } @@ -136,4 +138,4 @@ export function wrapIntoObservable(value: T | Promise| Observable): Obs } return of (value); -} \ No newline at end of file +} diff --git a/tools/public_api_guard/router/index.d.ts b/tools/public_api_guard/router/index.d.ts index a0201b1c093e5..f1666b8d32b27 100644 --- a/tools/public_api_guard/router/index.d.ts +++ b/tools/public_api_guard/router/index.d.ts @@ -85,7 +85,7 @@ export interface ExtraOptions { export declare type LoadChildren = string | LoadChildrenCallback; /** @stable */ -export declare type LoadChildrenCallback = () => Type | Promise> | Observable>; +export declare type LoadChildrenCallback = () => Type | NgModuleFactory | Promise> | Observable>; /** @stable */ export declare class NavigationCancel {