If you are using ngModel, but the form cannot find the object to populate data, then you get the following error:
ERROR TypeError: Cannot read property 'variable' of undefined
To resolve this error you need to check if the object exists and only then use ngModel. The easiest way to do this is by adding a '?' after the object. See example below:
Change
ERROR TypeError: Cannot read property 'variable' of undefined
To resolve this error you need to check if the object exists and only then use ngModel. The easiest way to do this is by adding a '?' after the object. See example below:
Change
[ngModel]="object.variable"
to
[ngModel]="object?.variable"
This will check if object exists and use it only if it exists.
Comments
Post a Comment