fix(ivy): providers should not be inherited (#27013)

PR Close #27013
This commit is contained in:
Kara Erickson
2018-11-08 11:26:28 -08:00
committed by Andrew Kushnir
parent 83c9bff242
commit 2f36a9591d
9 changed files with 146 additions and 35 deletions

View File

@ -146,7 +146,7 @@ export function InheritDefinitionFeature(definition: DirectiveDef<any>| Componen
const features = superDef.features;
if (features) {
for (const feature of features) {
if (feature && feature !== InheritDefinitionFeature) {
if (feature && feature.ngInherit) {
(feature as DirectiveDefFeature)(definition);
}
}

View File

@ -8,7 +8,7 @@
import {SimpleChange} from '../../change_detection/change_detection_util';
import {OnChanges, SimpleChanges} from '../../metadata/lifecycle_hooks';
import {DirectiveDef} from '../interfaces/definition';
import {DirectiveDef, DirectiveDefFeature} from '../interfaces/definition';
const PRIVATE_PREFIX = '__ngOnChanges_';
@ -106,6 +106,10 @@ export function NgOnChangesFeature<T>(definition: DirectiveDef<T>): void {
definition.doCheck = onChangesWrapper(definition.doCheck);
}
// This option ensures that the ngOnChanges lifecycle hook will be inherited
// from superclasses (in InheritDefinitionFeature).
(NgOnChangesFeature as DirectiveDefFeature).ngInherit = true;
function onChangesWrapper(delegateHook: (() => void) | null) {
return function(this: OnChangesExpando) {
const simpleChanges = this[PRIVATE_PREFIX];

View File

@ -307,8 +307,16 @@ export interface PipeDef<T> {
export type PipeDefWithMeta<T, Name extends string> = PipeDef<T>;
export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T>) => void;
export type ComponentDefFeature = <T>(componentDef: ComponentDef<T>) => void;
export interface DirectiveDefFeature {
<T>(directiveDef: DirectiveDef<T>): void;
ngInherit?: true;
}
export interface ComponentDefFeature {
<T>(componentDef: ComponentDef<T>): void;
ngInherit?: true;
}
/**
* Type used for directiveDefs on component definition.