angular/modules/@angular/router-deprecated/src/router_providers_common.ts
Tobias Bosch 8e6091de6c refactor(core): use ngOnDestroy in providers
Note about the addition of `beforeEach(fakeAsync(inject(…))))` in some tests:
`ApplicationRef` is now using `ngOnDestroy` and there is eager,
including all of its dependencies which contain `NgZone`.
The additional `fakeAsync` in `beforeEach` ensures that `NgZone`
uses the fake async zone as parent, and not the root zone.

BREAKING CHANGE (via deprecations):
- `ApplicationRef.dispose` is deprecated. Destroy the module that was
   created during bootstrap instead by calling `NgModuleRef.destroy`.
- `AplicationRef.registerDisposeListener` is deprecated.
   Use the `ngOnDestroy` lifecycle hook for providers or
   `NgModuleRef.onDestroy` instead.
- `disposePlatform` is deprecated. Use `destroyPlatform` instead.
- `PlatformRef.dipose()` is deprecated. Use `PlatformRef.destroy()`
   instead.
- `PlatformRef.registerDisposeListener` is deprecated. Use
  `PlatformRef.onDestroy` instead.
- `PlaformRef.diposed` is deprecated. Use `PlatformRef.destroyed`
  instead.
2016-08-02 11:23:26 -07:00

45 lines
1.4 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 {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';
import {ApplicationRef} from '@angular/core';
import {BaseException} from '../src/facade/exceptions';
import {Type} from '../src/facade/lang';
import {ROUTER_PRIMARY_COMPONENT, RouteRegistry} from './route_registry';
import {RootRouter, Router} from './router';
/**
* The Platform agnostic ROUTER PROVIDERS
*/
export const ROUTER_PROVIDERS_COMMON: any[] = [
RouteRegistry, {provide: LocationStrategy, useClass: PathLocationStrategy}, Location, {
provide: Router,
useFactory: routerFactory,
deps: [RouteRegistry, Location, ROUTER_PRIMARY_COMPONENT]
},
{
provide: ROUTER_PRIMARY_COMPONENT,
useFactory: routerPrimaryComponentFactory,
deps: [ApplicationRef]
}
];
function routerFactory(
registry: RouteRegistry, location: Location, primaryComponent: Type): RootRouter {
return new RootRouter(registry, location, primaryComponent);
}
function routerPrimaryComponentFactory(app: ApplicationRef): Type {
if (app.componentTypes.length == 0) {
throw new BaseException('Bootstrap at least one component before injecting Router.');
}
return app.componentTypes[0];
}