I have an API class:
export class ApiService {
constructor(public http: Http) { }
put(controller: string, method: string, data: Object) {
return this.http.put("http://127.0.0.1:8000",
JSON.stringify(data), {
})
.map(res => res.json())
.catch(err => {
return Observable.throw(err.json());
});
}
}
and an AccountService class:
export class AccountService {
api: ApiService;
constructor() {
this.api = new ApiService();
}
login(username: string, password: string) {
return this.api.put("accounts", "login", { username: username, password: password});
}
}
However when I run this example there are two problems:
1) The ApiService needs http in the constructor. Therefore this.api = new ApiService(); should provide Http which is not what I want.
How can I modify the ApiService so I don't have to provide Http to the constructor?
2) In the AccountService the this.api.put method is not found on the ApiService. Which I don't understand since I instantiated the ApiService into this.api