feat(core): add binding name to content changed error (#20352)

Adding the binding name to the error message recieved by the user gives
extra context on what exactly changed. The tests are also updated to
reflect the new error message.

PR Close #20352
This commit is contained in:
Xander Garbett 2017-11-11 08:40:17 +00:00 committed by Alex Eagle
parent 7e3f9a482a
commit d3bf54bdeb
3 changed files with 5 additions and 4 deletions

View File

@ -98,9 +98,10 @@ export function checkBindingNoChanges(
view: ViewData, def: NodeDef, bindingIdx: number, value: any) {
const oldValue = view.oldValues[def.bindingIndex + bindingIdx];
if ((view.state & ViewState.BeforeFirstCheck) || !devModeEqual(oldValue, value)) {
const bindingName = def.bindings[def.bindingIndex].name;
throw expressionChangedAfterItHasBeenCheckedError(
Services.createDebugContext(view, def.nodeIndex), oldValue, value,
(view.state & ViewState.BeforeFirstCheck) !== 0);
Services.createDebugContext(view, def.nodeIndex), `${bindingName}: ${oldValue}`,
`${bindingName}: ${value}`, (view.state & ViewState.BeforeFirstCheck) !== 0);
}
}

View File

@ -132,7 +132,7 @@ const addEventListener = '__zone_symbol__addEventListener';
value = 'v2';
expect(() => Services.checkNoChangesView(view))
.toThrowError(
`ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'v1'. Current value: 'v2'.`);
`ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'a: v1'. Current value: 'a: v2'.`);
});
it('should support detaching and attaching component views for dirty checking', () => {

View File

@ -145,7 +145,7 @@ import {compViewDef, compViewDefFactory, createAndGetRootNodes, createEmbeddedVi
childValue = 'v2';
expect(() => Services.checkNoChangesView(parentView))
.toThrowError(
`ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'v1'. Current value: 'v2'.`);
`ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'name: v1'. Current value: 'name: v2'.`);
});
it('should destroy embedded views', () => {