我試圖調用與ionic2的API,數據提供程序看起來像this.the服務返回對象數組。當我提供應用程序時,數據不顯示在HTML模板中。我如何解決這個問題。API調用與ionic2問題
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class VideoService {
videos: any;
constructor(public http: Http) {
console.log('Hello videoService Provider');
}
getVideos(){
this.http.get('http://mizikjams-lorisson.rhcloud.com/api/videos.json')
.map(res => res.json()).subscribe(data => {
this.videos= data.videos;
console.log(this.videos);
});
}
}
這裏的HTML模板代碼
<ion-content class=" mainpage card-background-page ">
<ion-list>
<ion-item *ngFor="let video of videos">
<ion-avatar item-left>
<img src="{{video.image}}">
</ion-avatar>
<h2>{{video.title}}</h2>
</ion-item>
</ion-list>
<div class="floatingbtn">
<ion-fab bottom right edge >
<button ion-fab color="orange" (click)="search();"><ion-icon name="search"></ion-icon></button>
</ion-fab>
</div>
</ion-content>
看起來你看過 「視頻」,並讓他們在服務。你有沒有使用這項服務的組件?和這個HTML代碼,它是否附加到任何組件/頁面? – MorKadosh