DataService的
import { Injectable } from '@angular/core';
import { Http, RequestOptions, Headers } from "@angular/http";
import { environment } from "../../environments/environment";
import 'rxjs/add/operator/map';
@Injectable()
export class DataService {
public options: RequestOptions;
constructor(protected url: string, protected http: Http) {
}
getAll() {
return this.http.get(this.url, this.options)
.map(
response => response.json()
)
}
get(id: string) {
return this.http.get(this.url + '/' + id, this.options)
.map(response => {
return response;
})
}
create(resource) {
return this.http.post(this.url, resource, this.options)
.map(response => {
return response;
})
} …Run Code Online (Sandbox Code Playgroud)