例一:
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { User } from "./model/User";
import { map } from 'rxjs/operators';
import { Http, Response, Headers, RequestOptions, URLSearchParams } from '@angular/http';
@Injectable({
providedIn: 'root'
})
export class UserService {
public userListURL = "api/users";
constructor(public http: Http) {}
public getUsers():Observable<User[]> {
return this.http.get(this.userListURL)
.pipe(
map((res: Response) => res.json().data as User[])
)
}
}