When working with my JSON API in my services, I need to pass the data to my models. What is the most efficient way to accomplish this task?
Currently, I am following this process:
import { Attachment } from '.';
export class Contact {
id: number;
attachments: Attachment[] = [];
static fromJSON(data) {
let contact = new Contact();
contact.id = data.id;
// Attachments?
for(let attachment of data.attachments) {
contact.attachments.push( Attachment.fromJSON(attachment) );
}
return contact;
}
}
}
Any suggestions on better approaches?