Trust me, it works. I use this way for years and it’s gold.
Details:
If you use this.myModel = JSON.parse(jsonString);
you’ll have an instance of MyModel with fields but no methods or other members.
The following way instanciates MyModel with all its members on the regular way and appends the values to the fields of the actual instance of MyModel.
this.myModel = Object.create(MyModel.prototype);
Object.assign(this.myModel, JSON.parse(jsonString));
Two lines that saves your day
Back to question:
Yeah … the Model has a private parameter in the constructor for an instance pulled from the DI. Why does it need to be set, when instanciated with new
?
If I change the consturctor to something like constructor(private myService?: MyService)
then this.myService
is undefined
every time (no automated instance-pull from the DI).
Isn’t there another way to get the service instance out of the DI?