Well I have problem with my app. I work on some basic movie app and I can’t fetch data from API with id parameter. My code look like this.
Home.ts
goToMovie(single: any) {
let id = single;
console.log(id);
this.nav.push(SinglePage, {id: id});
}
Single.ts
export class SinglePage {
data: Movies = <Movies>{};
id: any;
constructor(public navCtrl: NavController,
public navParams: NavParams,
private movies: MoviesServiceProvider) {}
ionViewDidLoad() {
this.id = this.navParams.get("id");
this.movies.getMovie(this.id)
.then(res => { this.id = res[0]; });
console.log(this.id);
}
}
Single.html
<ion-header>
<ion-navbar>
<ion-title>single</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding *ngIf="data">
<p>{{data?.title}}</p>
</ion-content>
Interface.ts
export interface Movies {
id: number,
title: string,
description: string,
link: string,
image: string,
}
Service.ts
getMovie(id: number): Promise<Movies> {
return this.http.get('http://localhost:8000/api/movie/' + id)
.toPromise()
.then(response => response.json().data as Movies);
}
My problem is that nothing is rendered in view of single.html. In console I get expected results, values from id’s are correct. Also I don’t get any errors so if anybody knows what is problem I would be very grateful. I usually work in PHP and I didn’t work in Ionic for very long time.