import { Http } from '@angular/http'; import { Injectable } from "@angular/core"; import 'rxjs/add/operator/toPromise'; @Injectable() export class ApiContainerService { constructor(public http: Http) { } public getApi(url: string): Promise { return this.http.get(url).toPromise() .then(response => response.json().api) .catch(this.handleError); } private handleError(error: any): Promise { console.error('An error occurred', error); // for demo purposes only return Promise.reject(error.message || error); } }