UNPKG

tns-template-master-detail-kinvey-ng

Version:

Master-detail interface to display collection of items from Kinvey and inspect and edit selected item properties.

31 lines (22 loc) 733 B
import { Injectable } from "@angular/core"; import { Car } from "./car.model"; import { CarService } from "./car.service"; @Injectable({ providedIn: "root" }) export class CarEditService { private _editModel: Car; constructor(private _carService: CarService) {} startEdit(id: string): Car { this._editModel = null; return this.getEditableCarById(id); } getEditableCarById(id: string): Car { if (!this._editModel || this._editModel.id !== id) { const car = this._carService.getCarById(id); // get fresh editable copy of car model this._editModel = new Car(car); } return this._editModel; } }