I have a model that consists of multiple properties, and I aim to set all these properties with a default value of either empty or null.
Here is an example of my Model:
export class MyModel {
name: string;
jerseyNumber: number;
etc...
}
In my Component:
public myObject: MyModel = new MyModel();
Upon initializing myForm, the console.log output shows MyForm {}
:
However, what I actually desire is for each property within myForm to be automatically initialized with a default value, instead of being empty. I am aware that I can achieve this manually by doing this:
myObject.name = null;
myObject.jerseyNumber = null;
Nevertheless, I am curious if there is a way to programmatically accomplish this task since MyModel comprises numerous properties, which makes manual initialization appear inefficient.
Is there a method available to initialize all property values for a variable of type MyModel
?
Thank you in advance!