Typescript method on class undefined
You are probably trying to call this method on an object dynamically casted from a JSON
. Dynamically casted object
does not have the method defined in the class, they just respect the contract
and have the property.
The only way to make your current code work is to create a new instance of Contact
instead of just casting it with <Contact> yourObject
;
The solution would be to do something like this:
let contactsList: Contact[] = [];
yourServiceReturn.ForEach(c => contactsList[] = new Contact(c.name, c.surname));
// You can now call getFullName on the object stored on contactsList