import {Injectable} from "@angular/core"; import {Http, Headers} from "@angular/http"; import {Config} from "../config"; import {ApiObject} from "./apiobject"; import {Observable} from "rxjs/Rx"; import "rxjs/add/operator/map"; @Injectable() export class ##SERVICE## { private apiList: Array; constructor(private _http: Http) {} load() { this.apiList = new Array(); let headers = new Headers(); headers.append('Accept', 'application/json'); return this._http.get(Config.##APIBASEURL## + "##APIENDPOINT##", { headers: headers }) .map(res => res.json()) .map(data => { data.forEach((item) => { this.apiList.push( new ApiObject( ##API-FIELDS## )); }); return this.apiList; }) .catch(this.handleErrors); } getListItem(index: number) { return this.apiList[index]; } handleErrors(error: Response) { console.log("ERROR at api-list.service.ts: " + JSON.stringify(error.json())); return Observable.throw(error); } }