fix(ivy): call onChanges before onInit (#21793)

PR Close #21793
This commit is contained in:
Kara Erickson
2018-01-26 13:38:21 -08:00
committed by Jason Aden
parent d3d3f7191a
commit dcca799dbb
2 changed files with 31 additions and 7 deletions

View File

@ -99,16 +99,26 @@ export function NgOnChangesFeature<T>(type: Type<T>): (definition: DirectiveDef<
}
});
}
definition.doCheck = (function(delegateDoCheck) {
// If an onInit hook is defined, it will need to wrap the ngOnChanges call
// so the call order is changes-init-check in creation mode. In subsequent
// change detection runs, only the check wrapper will be called.
if (definition.onInit != null) {
definition.onInit = onChangesWrapper(definition.onInit);
}
definition.doCheck = onChangesWrapper(definition.doCheck);
function onChangesWrapper(delegateHook: (() => void) | null) {
return function(this: OnChangesExpando) {
let simpleChanges = this[PRIVATE_PREFIX];
if (simpleChanges != null) {
this.ngOnChanges(simpleChanges);
this[PRIVATE_PREFIX] = null;
}
delegateDoCheck && delegateDoCheck.apply(this);
delegateHook && delegateHook.apply(this);
};
})(proto.ngDoCheck);
}
};
}