Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { Headers, Http } from '@angular/http';
- import 'rjxs/add/operator/toPromise';
- import { Car } from './garage/car.model';
- @Injectable()
- export class DataServiceService {
- private headers = new Headers({'Content-Type': 'application/json'});
- private carsUrl = 'localhost:8080/geallcars'; // URL to web api
- constructor(private http: Http) { }
- getCars(): Promise<Car[]> {
- return this.http.get(this.carsUrl)
- .toPromise()
- .then(response => response.json().data as Car[])
- .catch();
- }
- geCar(id: number): Promise<Car> {
- const url = `${this.carsUrl}/${id}`;
- return this.http.get(url)
- .toPromise()
- .then(response => response.json().data as Car)
- .catch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement