X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ export class DynamicComponentLoader_ extends DynamicComponentLoader {
var component = this._viewManager.getComponent(newLocation);

var dispose = () => {
this._viewManager.destroyRootHostView(hostViewRef);
if (isPresent(onDispose)) {
onDispose();
}
this._viewManager.destroyRootHostView(hostViewRef);
};
return new ComponentRef_(newLocation, component, type, injector, dispose);
});
Expand Down
20 changes: 19 additions & 1 deletion modules/angular2/test/platform/bootstrap_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import {IS_DART, isPresent, stringify} from 'angular2/src/facade/lang';
import {bootstrap} from 'angular2/platform/browser';
import {ApplicationRef} from 'angular2/src/core/application_ref';
import {Component, Directive, View, platform} from 'angular2/core';
import {Component, Directive, View, OnDestroy, platform} from 'angular2/core';
import {BROWSER_PROVIDERS, BROWSER_APP_PROVIDERS} from 'angular2/platform/browser';
import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {DOCUMENT} from 'angular2/render';
Expand Down Expand Up @@ -67,6 +67,15 @@ class HelloRootMissingTemplate {
class HelloRootDirectiveIsNotCmp {
}

@Component({selector: 'hello-app'})
@View({template: ''})
class HelloOnDestroyTickCmp implements OnDestroy {
appRef: ApplicationRef;
constructor(@Inject(ApplicationRef) appRef) { this.appRef = appRef; }

onDestroy(): void { this.appRef.tick(); }
}

class _ArrayLogger {
res: any[] = [];
log(s: any): void { this.res.push(s); }
Expand Down Expand Up @@ -163,6 +172,15 @@ export function main() {
});
}));

it('should not crash if change detection is invoked when the root component is disposed',
inject([AsyncTestCompleter], (async) => {
bootstrap(HelloOnDestroyTickCmp, testProviders)
.then((ref) => {
expect(() => ref.dispose()).not.toThrow();
async.done();
});
}));

it('should unregister change detectors when components are disposed',
inject([AsyncTestCompleter], (async) => {
var app = platform(BROWSER_PROVIDERS).application([BROWSER_APP_PROVIDERS, testProviders]);
Expand Down
X Tutup