@@ -150,6 +150,11 @@ export function platformCommon(bindings?: Array<Type | Provider | any[]>, initia
150150 * explicitly by calling {@link platform}().
151151 */
152152export abstract class PlatformRef {
153+ /**
154+ * Register a listener to be called when the platform is disposed.
155+ */
156+ abstract registerDisposeListener ( dispose : ( ) => void ) : void ;
157+
153158 /**
154159 * Retrieve the platform {@link Injector}, which is the parent injector for
155160 * every Angular application on the page and provides singleton providers.
@@ -210,9 +215,12 @@ export abstract class PlatformRef {
210215export class PlatformRef_ extends PlatformRef {
211216 /** @internal */
212217 _applications : ApplicationRef [ ] = [ ] ;
218+ _disposeListeners : Function [ ] = [ ] ;
213219
214220 constructor ( private _injector : Injector , private _dispose : ( ) => void ) { super ( ) ; }
215221
222+ registerDisposeListener ( dispose : ( ) => void ) : void { this . _disposeListeners . push ( dispose ) ; }
223+
216224 get injector ( ) : Injector { return this . _injector ; }
217225
218226 application ( bindings : Array < Type | Provider | any [ ] > ) : ApplicationRef {
@@ -259,6 +267,7 @@ export class PlatformRef_ extends PlatformRef {
259267
260268 dispose ( ) : void {
261269 this . _applications . forEach ( ( app ) => app . dispose ( ) ) ;
270+ this . _disposeListeners . forEach ( ( dispose ) => dispose ( ) ) ;
262271 this . _dispose ( ) ;
263272 }
264273
@@ -278,6 +287,11 @@ export abstract class ApplicationRef {
278287 */
279288 abstract registerBootstrapListener ( listener : ( ref : ComponentRef ) => void ) : void ;
280289
290+ /**
291+ * Register a listener to be called when the application is disposed.
292+ */
293+ abstract registerDisposeListener ( dispose : ( ) => void ) : void ;
294+
281295 /**
282296 * Bootstrap a new component at the root level of the application.
283297 *
@@ -326,6 +340,7 @@ export abstract class ApplicationRef {
326340
327341export class ApplicationRef_ extends ApplicationRef {
328342 private _bootstrapListeners : Function [ ] = [ ] ;
343+ private _disposeListeners : Function [ ] = [ ] ;
329344 private _rootComponents : ComponentRef [ ] = [ ] ;
330345 private _rootComponentTypes : Type [ ] = [ ] ;
331346
@@ -337,6 +352,8 @@ export class ApplicationRef_ extends ApplicationRef {
337352 this . _bootstrapListeners . push ( listener ) ;
338353 }
339354
355+ registerDisposeListener ( dispose : ( ) => void ) : void { this . _disposeListeners . push ( dispose ) ; }
356+
340357 bootstrap ( componentType : Type ,
341358 providers ?: Array < Type | Provider | any [ ] > ) : Promise < ComponentRef > {
342359 var completer = PromiseWrapper . completer ( ) ;
@@ -380,6 +397,7 @@ export class ApplicationRef_ extends ApplicationRef {
380397 dispose ( ) : void {
381398 // TODO(alxhub): Dispose of the NgZone.
382399 this . _rootComponents . forEach ( ( ref ) => ref . dispose ( ) ) ;
400+ this . _disposeListeners . forEach ( ( dispose ) => dispose ( ) ) ;
383401 this . _platform . _applicationDisposed ( this ) ;
384402 }
385403
0 commit comments