In my services I have to pass the information served by my JSON api to my models. What is the best way to do this?
At the moment I am doing this:
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;
}
}
}
Are there better ideas?