So this is a pretty abstract example, but let's take the following model & service definitions:
Model/Object definition - car.ts
... /*imports*/
export class Car{
color: string;
wheels: number;
oilChangeDate: Date;
tyreChangeDate: Date;
... /*Additional properties*/
}
Service - car.service.ts
@Injectable()
export class CarService{
currentCar: Car;
constructor(http: Http){
... /*Initialization*/
}
...
serviceCurrentVehicle(){
currentCar.oilChangeDate = new Date();
currentCar.tyreChangeDate = new Date();
/* Some http request */
}
}
Questions
- Is it against Angular 2/4 style/design guides to move the logic behind serviceCurrentVehicle to the model definition? Why?
- Is it against Angular 2/4 style/design guides in general to have logic attached to the model definitions? And if not, how does one access a service while maintaining the constructor of the object? (i.e. without dependency injection)
I have looked at posts similar to this prior to creating this question.
EDIT: Came across this post on OAuth earlier too which is the kind of thing I'm aiming to create, but (a) the tutorial doesn't include the code for calling the HTTP request when saving a User and (b) I can't find any supporting references to this kind of domain model w/ business logic in the official documentation/style guides.
Cheers
EDIT 2: So it's over a year since I created this, but there still isn't any decent resources I've come across for this. I implemented a model definition in our system, and I'm looking for ways to improve it at the moment since it's enterprise level.