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 @@ -73,7 +73,9 @@ export class DynamicComponentLoader {

var dispose = () => {
var index = viewContainer.indexOf(hostViewRef);
viewContainer.remove(index);
if (index !== -1) {
viewContainer.remove(index);
}
};
return new ComponentRef(newLocation, component, dispose);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import {
viewRootNodes,
TestComponentBuilder,
RootTestComponent,
inspectElement
inspectElement,
By
} from 'angular2/test_lib';

import {Injector} from 'angular2/di';
import {NgIf} from 'angular2/directives';
import {Component, View, onDestroy} from 'angular2/annotations';
import * as viewAnn from 'angular2/src/core/annotations_impl/view';
import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
Expand Down Expand Up @@ -66,6 +68,37 @@ export function main() {
});
}));

it('should allow to dispose even if the location has been removed',
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
(loader, tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp, new viewAnn.View({
template: '<child-cmp *ng-if="ctxBoolProp"></child-cmp>',
directives: [NgIf, ChildComp]
}))
.overrideView(
ChildComp,
new viewAnn.View(
{template: '<location #loc></location>', directives: [Location]}))
.createAsync(MyComp)
.then((tc) => {
tc.componentInstance.ctxBoolProp = true;
tc.detectChanges();
var childCompEl = tc.query(By.css('child-cmp'));
loader.loadIntoLocation(DynamicallyLoaded, childCompEl.elementRef, 'loc')
.then(ref => {
expect(tc.nativeElement).toHaveText("Location;DynamicallyLoaded;");

tc.componentInstance.ctxBoolProp = false;
tc.detectChanges();
expect(tc.nativeElement).toHaveText("");

ref.dispose();
expect(tc.nativeElement).toHaveText("");
async.done();
});
});
}));

it('should update host properties',
inject(
[DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
Expand Down