fix(view_container): fixes injection on dynamically added views.
Closes #777
This commit is contained in:
parent
9b08ab3b3c
commit
2f015cc336
|
@ -74,8 +74,10 @@ export class ViewContainer {
|
||||||
'Cannot create views on a dehydrated ViewContainer');
|
'Cannot create views on a dehydrated ViewContainer');
|
||||||
// TODO(rado): replace with viewFactory.
|
// TODO(rado): replace with viewFactory.
|
||||||
var newView = this.defaultProtoView.instantiate(this.hostElementInjector, this._eventManager);
|
var newView = this.defaultProtoView.instantiate(this.hostElementInjector, this._eventManager);
|
||||||
|
// insertion must come before hydration so that element injector trees are attached.
|
||||||
|
this.insert(newView, atIndex);
|
||||||
newView.hydrate(this.appInjector, this.hostElementInjector, this.parentView.context);
|
newView.hydrate(this.appInjector, this.hostElementInjector, this.parentView.context);
|
||||||
return this.insert(newView, atIndex);
|
return newView;
|
||||||
}
|
}
|
||||||
|
|
||||||
insert(view, atIndex=-1): viewModule.View {
|
insert(view, atIndex=-1): viewModule.View {
|
||||||
|
|
|
@ -19,6 +19,8 @@ import {Decorator, Component, Viewport} from 'angular2/src/core/annotations/anno
|
||||||
import {Template} from 'angular2/src/core/annotations/template';
|
import {Template} from 'angular2/src/core/annotations/template';
|
||||||
import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility';
|
import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility';
|
||||||
|
|
||||||
|
import {If} from 'angular2/src/directives/if';
|
||||||
|
|
||||||
import {ViewContainer} from 'angular2/src/core/compiler/view_container';
|
import {ViewContainer} from 'angular2/src/core/compiler/view_container';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
|
@ -365,6 +367,29 @@ export function main() {
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should create a component that injects an @Ancestor through viewport directive', (done) => {
|
||||||
|
tplResolver.setTemplate(MyComp, new Template({
|
||||||
|
inline: `
|
||||||
|
<some-directive>
|
||||||
|
<p *if="true">
|
||||||
|
<cmp-with-ancestor #child></cmp-with-ancestor>
|
||||||
|
</p>
|
||||||
|
</some-directive>`,
|
||||||
|
directives: [SomeDirective, CompWithAncestor, If]
|
||||||
|
}));
|
||||||
|
|
||||||
|
compiler.compile(MyComp).then((pv) => {
|
||||||
|
createView(pv);
|
||||||
|
cd.detectChanges();
|
||||||
|
|
||||||
|
var subview = view.viewContainers[0].get(0);
|
||||||
|
var childComponent = subview.contextWithLocals.get('child');
|
||||||
|
expect(childComponent.myAncestor).toBeAnInstanceOf(SomeDirective);
|
||||||
|
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO support these tests with DART e.g. with Promise.catch (JS) transpiled to Future.catchError (DART)
|
// TODO support these tests with DART e.g. with Promise.catch (JS) transpiled to Future.catchError (DART)
|
||||||
|
|
Loading…
Reference in New Issue