fix(di): hostInjector and viewInjector support nested arrays

This commit is contained in:
vsavkin
2015-07-09 11:40:09 -07:00
parent b716046b97
commit 0ed5dd0d7b
6 changed files with 24 additions and 12 deletions
@@ -40,7 +40,7 @@ import {
Directive,
onDestroy
} from 'angular2/annotations';
import {bind, Injector, Binding, resolveBindings, Optional, Inject, Injectable, Self, Parent, Ancestor, Unbounded, self, InjectMetadata, ParentMetadata} from 'angular2/di';
import {bind, Injector, Binding, Optional, Inject, Injectable, Self, Parent, Ancestor, Unbounded, self, InjectMetadata, ParentMetadata} from 'angular2/di';
import {AppProtoView, AppView} from 'angular2/src/core/compiler/view';
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
import {ProtoViewRef} from 'angular2/src/core/compiler/view_ref';
@@ -486,6 +486,21 @@ export function main() {
expect(pei.getBindingAtIndex(1).key.token).toEqual("injectable1");
});
it("should collect view and host injectables from nested arrays", () => {
var pei = createPei(null, 0, [
DirectiveBinding.createFromType(
SimpleDirective,
new dirAnn.Component({
viewInjector: [[[bind('view').toValue('view')]]],
hostInjector: [[[bind('host').toValue('host')]]]
}))
], 0, true);
expect(pei.getBindingAtIndex(0).key.token).toBe(SimpleDirective);
expect(pei.getBindingAtIndex(1).key.token).toEqual("view");
expect(pei.getBindingAtIndex(2).key.token).toEqual("host");
});
it('should support an arbitrary number of bindings', () => {
var pei = createPei(null, 0, dynamicBindings);
@@ -1007,7 +1007,7 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp, new viewAnn.View({
template: `
<directive-providing-injectable>
<directive-providing-injectable >
<directive-consuming-injectable #consuming>
</directive-consuming-injectable>
</directive-providing-injectable>
@@ -1697,12 +1697,12 @@ class DirectiveWithTwoWayBinding {
class InjectableService {
}
@Directive({selector: 'directive-providing-injectable', hostInjector: [InjectableService]})
@Directive({selector: 'directive-providing-injectable', hostInjector: [[InjectableService]]})
@Injectable()
class DirectiveProvidingInjectable {
}
@Component({selector: 'directive-providing-injectable', viewInjector: [InjectableService]})
@Component({selector: 'directive-providing-injectable', viewInjector: [[InjectableService]]})
@View({template: ''})
@Injectable()
class DirectiveProvidingInjectableInView {