diff --git a/packages/core/src/render3/definition.ts b/packages/core/src/render3/definition.ts index d17049868d..e39abdb9b7 100644 --- a/packages/core/src/render3/definition.ts +++ b/packages/core/src/render3/definition.ts @@ -272,7 +272,13 @@ export function NgOnChangesFeature(inputPropertyNames?: {[key: string]: string}) this, PRIVATE_PREFIX, {value: simpleChanges = {}, writable: true}); } const isFirstChange = !this.hasOwnProperty(privateMinKey); - simpleChanges[propertyName] = new SimpleChange(this[privateMinKey], value, isFirstChange); + const currentChange: SimpleChange|undefined = simpleChanges[propertyName]; + if (currentChange) { + currentChange.currentValue = value; + } else { + simpleChanges[propertyName] = + new SimpleChange(this[privateMinKey], value, isFirstChange); + } if (isFirstChange) { // Create a place where the actual value will be stored and make it non-enumerable Object.defineProperty(this, privateMinKey, {value, writable: true}); diff --git a/packages/core/test/render3/define_spec.ts b/packages/core/test/render3/define_spec.ts index 2253dba899..6c9f6565e7 100644 --- a/packages/core/test/render3/define_spec.ts +++ b/packages/core/test/render3/define_spec.ts @@ -45,7 +45,7 @@ describe('define', () => { expect(myDir.valB).toEqual('works'); myDir.log.length = 0; (MyDirective.ngDirectiveDef as DirectiveDef).doCheck !.call(myDir); - const changeA = new SimpleChange('initValue', 'first', false); + const changeA = new SimpleChange(undefined, 'first', true); const changeB = new SimpleChange(undefined, 'second', true); expect(myDir.log).toEqual(['ngOnChanges', 'valA', changeA, 'valB', changeB, 'ngDoCheck']); }); @@ -75,7 +75,7 @@ describe('define', () => { myDir.valA = 'first'; myDir.valB = 'second'; (MyDirective.ngDirectiveDef as DirectiveDef).doCheck !.call(myDir); - const changeA1 = new SimpleChange('initValue', 'first', false); + const changeA1 = new SimpleChange(undefined, 'first', true); const changeB1 = new SimpleChange(undefined, 'second', true); expect(myDir.log).toEqual(['valA', changeA1, 'valB', changeB1]);