I'd like to have a model that updates the back-end by itself but when I import Http it is undefined.
import {Http, Headers} from "@angular/http";
export class Vehicle {
engine:string
id:number
constructor(private http:Http){
}
update() {
const body = JSON.stringify(engine);
const headers = new Headers();
headers.append('Content-Type', 'application/json');
return this._http.put('http://localhost/v1/vehicles/' + id, body, {headers: headers})
.map(response => response.json());
}
}
The idea then is to do something like:
var vehicle = new Vehicle();
vehicle.update(); //this then would update the back end
I've simplified the class to show what I'm after (not worried about the syntactical correctness necessarily in the above example).
In this scenario, it transpiles correctly and there are no errors BUT http is undefined.
I can achieve what I want in an ng2 service by getting the contents of the vehicle instance and then passing them onto the VehicleList service but was wondering if it's possible to do it right in the Vehicle class itself.