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:

committed by
Miško Hevery

parent
900a88b15d
commit
392d584572
@ -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 !;
|
||||
|
Reference in New Issue
Block a user