fix(element_injector): fixed element injector to inject view dependencies into its components
This commit is contained in:
parent
dd9b08cce8
commit
b6b52e62b2
|
@ -831,7 +831,7 @@ export class ElementInjector extends TreeNode<ElementInjector> {
|
|||
directParent(): ElementInjector { return this._proto.distanceToParent < 2 ? this.parent : null; }
|
||||
|
||||
private _isComponentKey(key: Key) {
|
||||
return this._proto._firstBindingIsComponent && key.id === this._proto._keyId0;
|
||||
return this._proto._firstBindingIsComponent && isPresent(key) && key.id === this._proto._keyId0;
|
||||
}
|
||||
|
||||
private _isDynamicallyLoadedComponentKey(key: Key) {
|
||||
|
@ -1134,7 +1134,11 @@ export class ElementInjector extends TreeNode<ElementInjector> {
|
|||
private _getByKey(key: Key, visibility: Visibility, optional: boolean, requestor: Key) {
|
||||
var ei = this;
|
||||
|
||||
var currentVisibility = LIGHT_DOM;
|
||||
var currentVisibility = this._isComponentKey(requestor) ?
|
||||
LIGHT_DOM_AND_SHADOW_DOM : // component can access both shadow dom
|
||||
// and light dom dependencies
|
||||
LIGHT_DOM;
|
||||
|
||||
var depth = visibility.depth;
|
||||
|
||||
if (!visibility.shouldIncludeSelf()) {
|
||||
|
@ -1144,9 +1148,7 @@ export class ElementInjector extends TreeNode<ElementInjector> {
|
|||
ei = ei._parent;
|
||||
} else {
|
||||
ei = ei._host;
|
||||
if (!visibility.crossComponentBoundaries) {
|
||||
currentVisibility = SHADOW_DOM;
|
||||
}
|
||||
currentVisibility = visibility.crossComponentBoundaries ? LIGHT_DOM : SHADOW_DOM;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1159,15 +1161,14 @@ export class ElementInjector extends TreeNode<ElementInjector> {
|
|||
|
||||
depth -= ei._proto.distanceToParent;
|
||||
|
||||
// we check only one mode with the SHADOW_DOM visibility
|
||||
if (currentVisibility === SHADOW_DOM) break;
|
||||
|
||||
if (isPresent(ei._parent)) {
|
||||
ei = ei._parent;
|
||||
} else {
|
||||
ei = ei._host;
|
||||
if (!visibility.crossComponentBoundaries) {
|
||||
currentVisibility = SHADOW_DOM;
|
||||
}
|
||||
currentVisibility = visibility.crossComponentBoundaries ? LIGHT_DOM : SHADOW_DOM;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -528,6 +528,16 @@ export function main() {
|
|||
expect(inj.get('injectable2')).toEqual('injectable1-injectable2');
|
||||
});
|
||||
|
||||
it("should instantiate components that depends on viewInjector dependencies", function () {
|
||||
var inj = injector([
|
||||
DirectiveBinding.createFromType(NeedsService,
|
||||
new DummyDirective({viewInjector: [
|
||||
bind('service').toValue('service')
|
||||
]}))
|
||||
], null, true);
|
||||
expect(inj.get(NeedsService).service).toEqual('service');
|
||||
});
|
||||
|
||||
it("should instantiate directives that depend on app services", function () {
|
||||
var appInjector = Injector.resolveAndCreate([
|
||||
bind("service").toValue("service")
|
||||
|
|
Loading…
Reference in New Issue