2016-07-06 14:02:16 -04:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
2016-07-18 06:50:31 -04:00
|
|
|
import {ComponentFactoryResolver, Injector, NgModuleFactoryLoader, OpaqueToken} from '@angular/core';
|
2016-07-06 14:02:16 -04:00
|
|
|
import {Observable} from 'rxjs/Observable';
|
|
|
|
import {fromPromise} from 'rxjs/observable/fromPromise';
|
|
|
|
|
|
|
|
import {Route} from './config';
|
2016-08-02 16:27:55 -04:00
|
|
|
import {flatten} from './utils/collection';
|
2016-07-13 21:12:59 -04:00
|
|
|
|
2016-07-18 06:50:31 -04:00
|
|
|
|
2016-07-06 19:19:52 -04:00
|
|
|
/**
|
|
|
|
* @deprecated use Routes
|
|
|
|
*/
|
2016-07-06 14:32:42 -04:00
|
|
|
export const ROUTER_CONFIG = new OpaqueToken('ROUTER_CONFIG');
|
2016-07-06 19:19:52 -04:00
|
|
|
export const ROUTES = new OpaqueToken('ROUTES');
|
2016-07-06 14:32:42 -04:00
|
|
|
|
2016-07-06 14:02:16 -04:00
|
|
|
export class LoadedRouterConfig {
|
2016-07-13 21:12:59 -04:00
|
|
|
constructor(
|
|
|
|
public routes: Route[], public injector: Injector,
|
|
|
|
public factoryResolver: ComponentFactoryResolver) {}
|
2016-07-06 14:02:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export class RouterConfigLoader {
|
2016-07-18 06:50:31 -04:00
|
|
|
constructor(private loader: NgModuleFactoryLoader) {}
|
2016-07-06 14:02:16 -04:00
|
|
|
|
2016-07-13 21:12:59 -04:00
|
|
|
load(parentInjector: Injector, path: string): Observable<LoadedRouterConfig> {
|
2016-07-06 14:02:16 -04:00
|
|
|
return fromPromise(this.loader.load(path).then(r => {
|
2016-07-13 21:12:59 -04:00
|
|
|
const ref = r.create(parentInjector);
|
|
|
|
return new LoadedRouterConfig(
|
2016-08-02 16:27:55 -04:00
|
|
|
flatten(ref.injector.get(ROUTES)), ref.injector, ref.componentFactoryResolver);
|
2016-07-06 14:02:16 -04:00
|
|
|
}));
|
|
|
|
}
|
2016-07-18 06:50:31 -04:00
|
|
|
}
|