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:
parent
54e75766ad
commit
4556532c26
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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', () => {
|
||||
|
@ -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', () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user