Skip to main content

Posts

Showing posts from April, 2019

Angular ngModel Error - TypeError: Cannot read property 'variable' of undefined

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 [ngModel] = "object.variable" to [ngModel] = "object?.variable" This will check if object exists and use it only if it exists.