mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
This contains major changes to the compiler, bootstrap of the platforms and test environment initialization. Main part of #10043 Closes #10164 BREAKING CHANGE: - Semantics and name of `@AppModule` (now `@NgModule`) changed quite a bit. This is actually not breaking as `@AppModules` were not part of rc.4. We will have detailed docs on `@NgModule` separately. - `coreLoadAndBootstrap` and `coreBootstrap` can't be used any more (without migration support). Use `bootstrapModule` / `bootstrapModuleFactory` instead. - All Components listed in routes have to be part of the `declarations` of an NgModule. Either directly on the bootstrap module / lazy loaded module, or in an NgModule imported by them.
49 lines
No EOL
1.7 KiB
TypeScript
49 lines
No EOL
1.7 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
import 'rxjs/add/operator/map';
|
|
import 'rxjs/add/operator/toPromise';
|
|
|
|
import {ComponentResolver} from '@angular/core';
|
|
import {Observable} from 'rxjs/Observable';
|
|
import {forkJoin} from 'rxjs/observable/forkJoin';
|
|
import {fromPromise} from 'rxjs/observable/fromPromise';
|
|
|
|
import {ActivatedRouteSnapshot, RouterStateSnapshot} from './router_state';
|
|
import {TreeNode} from './utils/tree';
|
|
|
|
export function resolve(
|
|
resolver: ComponentResolver, state: RouterStateSnapshot): Observable<RouterStateSnapshot> {
|
|
return resolveNode(resolver, state._root).map(_ => state);
|
|
}
|
|
|
|
function resolveNode(
|
|
resolver: ComponentResolver, node: TreeNode<ActivatedRouteSnapshot>): Observable<any> {
|
|
if (node.children.length === 0) {
|
|
return fromPromise(resolveComponent(resolver, <any>node.value).then(factory => {
|
|
node.value._resolvedComponentFactory = factory;
|
|
return node.value;
|
|
}));
|
|
|
|
} else {
|
|
const c = node.children.map(c => resolveNode(resolver, c).toPromise());
|
|
return forkJoin(c).map(_ => resolveComponent(resolver, <any>node.value).then(factory => {
|
|
node.value._resolvedComponentFactory = factory;
|
|
return node.value;
|
|
}));
|
|
}
|
|
}
|
|
|
|
function resolveComponent(
|
|
resolver: ComponentResolver, snapshot: ActivatedRouteSnapshot): Promise<any> {
|
|
if (snapshot.component && snapshot._routeConfig && typeof snapshot.component === 'string') {
|
|
return resolver.resolveComponent(<any>snapshot.component);
|
|
} else {
|
|
return Promise.resolve(null);
|
|
}
|
|
} |