在过去的4年里,我在与AngularJS 1.*一起工作之后,我正在尝试自学Angular2和TypeScript!我不得不承认我讨厌它,但我确信我的尤里卡时刻即将到来......无论如何,我已经在我的虚拟应用程序中编写了一个服务,它将从我写的服务JSON的虚拟后端获取http数据.
import {Injectable} from 'angular2/core';
import {Http, Headers, Response} from 'angular2/http';
import {Observable} from 'rxjs';
@Injectable()
export class UserData {
constructor(public http: Http) {
}
getUserStatus(): any {
var headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.get('/restservice/userstatus', {headers: headers})
.map((data: any) => data.json())
.catch(this.handleError);
}
getUserInfo(): any {
var headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.get('/restservice/profile/info', {headers: headers})
.map((data: any) => data.json())
.catch(this.handleError);
}
getUserPhotos(myId): any {
var headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.get(`restservice/profile/pictures/overview/${ myId }`, …Run Code Online (Sandbox Code Playgroud)