In my Angular project, I have created some custom form objects using interfaces in Typescript, with properties mostly being string or number types. These objects are used to populate a form using ngModel, and thus default values need to be assigned to the properties of these objects on the component side to avoid errors due to undefined object.
I am currently using interfaces to define the object shape and assign default values in the component, but I am exploring other options as well.
- One alternative is to use a Class to define the object and set default values in the constructor. This approach seems more organized and eliminates the need to manually assign default values in the component.
I would like to know if using a class is the preferred method for defining complex objects (with nested properties) when working with ngModel, and also if there are any other approaches to handle this issue effectively.