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.
This commit is contained in:
Tobias Bosch
2016-08-02 02:32:27 -07:00
parent ecdaded25f
commit 8e6091de6c
12 changed files with 150 additions and 106 deletions

View File

@ -36,7 +36,6 @@ export function setupRouter(
const componentType = ref.componentTypes[0];
const r = new Router(
componentType, resolver, urlSerializer, outletMap, location, injector, loader, config);
ref.registerDisposeListener(() => r.dispose());
if (opts.enableTracing) {
r.events.subscribe(e => {

View File

@ -196,6 +196,11 @@ export class Router {
this.config = config;
}
/**
* @internal
*/
ngOnDestroy() { this.dispose(); }
/**
* Disposes of the router.
*/