AUR0773
Error Message
AUR0773: Invalid @watch decorator change handler config. Method "<methodName>" not found in class <ClassName>
Where <methodName> is the name provided as the change handler, and <ClassName> is the name of the class where @watch was used.
Description
This error occurs when using the @watch decorator as a class decorator with a configuration object, and the changeHandler property in that configuration is a string, but there is no method with that specified name on the decorated class.
The @watch decorator needs a valid function (either provided directly or found by name on the class) to call when the watched expression changes.
Cause
This error specifically happens under these conditions:
@watchis used as a class decorator:@watch({...})(MyClass)or@watch({...}) class MyClass { ... }A configuration object is passed to
@watch.The configuration object has a
changeHandlerproperty that is a string (e.g.,{ changeHandler: 'myMethodName' }).The class (
MyClassin the example) does not have a method namedmyMethodName.
import { watch } from '@aurelia/runtime-html';
// Incorrect: 'valueChangedHandler' method does not exist on the class
@watch({
expression: 'value',
changeHandler: 'valueChangedHandler' // Typo or missing method
})
export class MyViewModel {
value: string = 'test';
// Missing the required 'valueChangedHandler' method
// valueChangedHandler(newValue, oldValue) { /* ... */ }
}
// Incorrect: changeHandler name mismatch
@watch({
expression: 'count',
changeHandler: 'handleCountChange'
})
export class Counter {
count: number = 0;
// Method exists, but name doesn't match the changeHandler string
countChanged(newValue, oldValue) {
console.log(newValue, oldValue);
}
}Solution
Verify Method Name: Ensure the string provided in the
changeHandlerproperty exactly matches the name of an existing method on the decorated class. Check for typos.Implement the Method: If the method is missing, implement it on the class with the correct name.
Use Method Decorator: Alternatively, apply
@watchdirectly to the handler method itself instead of using it as a class decorator with a stringchangeHandler. This is often simpler and less prone to typos.
Example
Debugging Tips
Carefully compare the string value of the
changeHandlerproperty in the@watchconfiguration object with the method names defined in your class.Check for subtle differences like capitalization or spelling errors.
Consider refactoring to use
@watchas a method decorator on the handler function, which eliminates the need for the string name lookup.
Last updated
Was this helpful?