import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class EpisodeService {
data: any;
constructor(private http: Http) {
this.data = null;
}
load() {
if (this.data) {
// already loaded data
return Promise.resolve(this.data);
}
// don't have the data yet
let body = JSON.stringify({});
let headers = new Headers();
headers.append('app-id', '');
headers.append('app-key', '');
headers.append('Content-Type', 'application/json');
return new Promise(resolve => {
// We're using Angular Http provider to request the data,
// then on the response it'll map the JSON data to a parsed JS object.
// Next we process the data and resolve the promise with the new data.
this.http.post('http://twit.tv/api/v1.0/episodes?range=10', body, {headers: headers})
.map(res => res.json())
.subscribe(data => {
this.data = data.episodes;
// we've got back the raw data, now generate the core schedule data
// and save the data for later reference
//this.data = data;
resolve(this.data);
});
});
}
}
Removed keys for security reasons
However on the page it should display on i get a blank page
latest.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { EpisodeService } from '../../providers/episode-service/episode-service';
@Component({
templateUrl: 'build/pages/latest/latest.html',
providers: [EpisodeService]
})
export class LatestPage {
public people: any;
constructor(public episodeService: EpisodeService){
this.loadPeople();
}
loadPeople(){
this.episodeService.load()
.then(data => {
this.people = data;
});
}
}