Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { Headers, Http } from '@angular/http';
  3.  
  4. import 'rjxs/add/operator/toPromise';
  5.  
  6. import { Car } from './garage/car.model';
  7. @Injectable()
  8. export class DataServiceService {
  9.  
  10. private headers = new Headers({'Content-Type': 'application/json'});
  11. private carsUrl = 'localhost:8080/geallcars'; // URL to web api
  12.  
  13. constructor(private http: Http) { }
  14.  
  15. getCars(): Promise<Car[]> {
  16. return this.http.get(this.carsUrl)
  17. .toPromise()
  18. .then(response => response.json().data as Car[])
  19. .catch();
  20. }
  21.  
  22.  
  23. geCar(id: number): Promise<Car> {
  24. const url = `${this.carsUrl}/${id}`;
  25. return this.http.get(url)
  26. .toPromise()
  27. .then(response => response.json().data as Car)
  28. .catch();
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement