Service:
@Injectable()
export class Service {
constructor(private http: Http) { }
getCars(){
return this.http.get...
}
getById
I suppose the likely problem is located here:
this._service.getById(id)
.subscribe(car => {
this.car = car; // you just init object like { id: '1', name: 'name'}
});
Probably your service looks like this:
getById(id: string) {
return this.http.get('app/car.json')
.map(data => data.json());
}
Try to get Car
model from service like this:
getById(id: string) {
return this.http.get('app/car.json')
.map(data => data.json())
.map(car => new Car(car.id, car.name)); <== add this line
}
This way car
will be instance of Car
class and will have appropriate methods like getBrands
, addBrand
...
Hope it helps!