"angular2": "2.0.0-beta.17",
How can I import { Http, Response } from 'angular2/http'; in my Base class and use http in the child classes?
Is there a way to achieve this?
P.S. I'm open to hacks, workarounds, and unconventional solutions.
The base class:
import { Http, Response } from 'angular2/http';
export class ServiceBase {
constructor (private http: Http) {}
}
And a child class:
import { ApiServiceBase } from '../../api-service-base';
import { Injectable } from 'angular2/core';
// import { Http, Response } from 'angular2/http';
import { AuthUser } from './auth_user';
import { Observable } from 'rxjs/Observable';
import { Headers, RequestOptions } from 'angular2/http';
import 'rxjs/add/operator/toPromise';
@Injectable()
export class LoginService extends ApiServiceBase {
constructor () {
super();
}
private url = 'http://localhost:8080/api/signin';
login (user: AuthUser): Promise<AuthUser> {
let body = JSON.stringify(user);
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.url, body, options)
.toPromise()
.then(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response) {
console.log(res);
if (res.status < 200 || res.status >= 300) {
throw new Error('Bad response status: ' + res.status);
}
let body = res.json();
return body.data || { };
}
private handleError (error: any) {
}
}