Let's say I have a class Foo
:
export class Foo {
name: string;
printName(): void {
console.log(this.name);
}
}
Now the problem is that when my FooService
gets a Foo
from my backend as JSON and creates a Foo object out of it, it doesn't have printName()
because there's no such thing in the JSON object.
How should I arrange this (in the context of Angular 2)? Do I have to create my methods outside the class so that they just take a Foo
as an argument?
In Java, for example, it's perfectly fine that DTO's have methods.