feat(ElementInjector): change ElementInjector so @parent and @ancestor do not include self.
This commit is contained in:
parent
b87891d77c
commit
ac8351b7bc
|
@ -377,6 +377,12 @@ export class ElementInjector extends TreeNode {
|
|||
*/
|
||||
_getByKey(key:Key, depth:int, requestor:Key) {
|
||||
var ei = this;
|
||||
|
||||
if (! this._shouldIncludeSelf(depth)) {
|
||||
depth -= 1;
|
||||
ei = ei._parent;
|
||||
}
|
||||
|
||||
while (ei != null && depth >= 0) {
|
||||
var specObj = ei._getSpecialObjectByKeyId(key.id);
|
||||
if (specObj !== _undefined) return specObj;
|
||||
|
@ -387,6 +393,7 @@ export class ElementInjector extends TreeNode {
|
|||
ei = ei._parent;
|
||||
depth -= 1;
|
||||
}
|
||||
|
||||
if (isPresent(this._host) && this._host._isComponentKey(key)) {
|
||||
return this._host.getComponent();
|
||||
} else {
|
||||
|
@ -400,6 +407,10 @@ export class ElementInjector extends TreeNode {
|
|||
}
|
||||
}
|
||||
|
||||
_shouldIncludeSelf(depth:int) {
|
||||
return depth === 0;
|
||||
}
|
||||
|
||||
_getSpecialObjectByKeyId(keyId:int) {
|
||||
var staticKeys = StaticKeys.instance();
|
||||
if (keyId === staticKeys.viewId) return this._view;
|
||||
|
|
|
@ -225,6 +225,12 @@ export function main() {
|
|||
expect(d.dependency).toBeAnInstanceOf(Directive);
|
||||
});
|
||||
|
||||
it("should not return parent's directives on self", function () {
|
||||
expect(() => {
|
||||
injector([Directive, NeedDirectiveFromParent]);
|
||||
}).toThrowError();
|
||||
});
|
||||
|
||||
it("should get directives from ancestor", function () {
|
||||
var child = parentChildInjectors([Directive], [NeedDirectiveFromAncestor]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue