I have a TypeScript class in angular looking like this:
import {HotelModel} from './hotel.model';
import {LocationModel} from './location.model';
export class CountryModel {
id: number;
name: string;
description: string;
countryFlagImagePath: string;
themeFotoImagePath: string;
hotels: HotelModel[];
locations: LocationModel[];
constructor(values: Object = {}) {
Object.assign(this, values);
}
}
I retrieve data from API, where the model object are similiar to these ones.
The assign in the constructor works fine until I reach the nested model properties.
For example array of HotelModel. Then It just assigns the data to array of plain objects instead of array of HotelModel.
Is there any easy way (similiar to the object assign where I do not need to care about assigning every simple class member) for the nested properties? (If possible for properties nested X times)?