feat(di): added optional self parameter to Parent, Ancestor, and Unbounded
This commit is contained in:
@@ -103,6 +103,12 @@ class NeedsDirectiveFromParent {
|
||||
constructor(@Parent() dependency: SimpleDirective) { this.dependency = dependency; }
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
class NeedsDirectiveFromParentOrSelf {
|
||||
dependency: SimpleDirective;
|
||||
constructor(@Parent({self:true}) dependency: SimpleDirective) { this.dependency = dependency; }
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
class NeedsDirectiveFromAncestor {
|
||||
dependency: SimpleDirective;
|
||||
@@ -640,12 +646,21 @@ export function main() {
|
||||
expect(d.dependency).toBeAnInstanceOf(SimpleDirective);
|
||||
});
|
||||
|
||||
it("should not return parent's directives on self", () => {
|
||||
it("should not return parent's directives on self by default", () => {
|
||||
expect(() => {
|
||||
injector(ListWrapper.concat([SimpleDirective, NeedsDirectiveFromParent], extraBindings));
|
||||
}).toThrowError(containsRegexp(`No provider for ${stringify(SimpleDirective) }`));
|
||||
});
|
||||
|
||||
it("should return parent's directives on self when explicitly specified", () => {
|
||||
var inj = injector(ListWrapper.concat([SimpleDirective, NeedsDirectiveFromParentOrSelf], extraBindings));
|
||||
|
||||
var d = inj.get(NeedsDirectiveFromParentOrSelf);
|
||||
|
||||
expect(d).toBeAnInstanceOf(NeedsDirectiveFromParentOrSelf);
|
||||
expect(d.dependency).toBeAnInstanceOf(SimpleDirective);
|
||||
});
|
||||
|
||||
it("should get directives from ancestor", () => {
|
||||
var child = parentChildInjectors(ListWrapper.concat([SimpleDirective], extraBindings),
|
||||
[NeedsDirectiveFromAncestor]);
|
||||
|
||||
Reference in New Issue
Block a user