fix(core): allow directives to inject the component’s ChangeDetectorRef. (#16394)

When a directive lives on the same element as a component
(e.g. `<my-comp myDir>`), the directive was not able to get hold
of the `ChangeDetectorRef` of the component on that element. However,
as directives are supposed to decorate components, this is incorrect.

This commit enables this use case.

Closes #12816
This commit is contained in:
Tobias Bosch
2017-04-27 16:13:47 -07:00
committed by Miško Hevery
parent 900a88b15d
commit 392d584572
2 changed files with 46 additions and 0 deletions

View File

@ -355,6 +355,12 @@ export function resolveDep(
}
const tokenKey = depDef.tokenKey;
if (tokenKey === ChangeDetectorRefTokenKey) {
// directives on the same element as a component should be able to control the change detector
// of that component as well.
allowPrivateServices = !!(elDef && elDef.element !.componentView);
}
if (elDef && (depDef.flags & DepFlags.SkipSelf)) {
allowPrivateServices = false;
elDef = elDef.parent !;