Angular 2/4/5 Model Logic

So, this is a pretty abstract example, but let me take the following definitions of models and services:

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 guidelines to move the logic behind serviceCurrentVehicle into a model definition? Why?
  • Is it against the Angular 2/4 style / design guide as a whole to have logic tied to model definitions? And if not, how can I access the service while saving the constructor of the object? (i.e. without dependency injection)

I reviewed posts similar to before posting this question.

EDIT: OAuth , , , () HTTP- () - ​​ /.

+4

Source: https://habr.com/ru/post/1682824/


All Articles