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