Ionic2中未找到DataApi数据(未在Html中显示)

时间:2017-05-10 13:43:05

标签: json api ionic2 ngfor

我正在为Ionic开发一个应用程序2.我正在从JSON拍照,我在console.log中列出数据。但是它们没有显示在HTML.Error中(GET http://ukopuz.com/[object%20Object] 404 (未找到))我哪里出错?

数据-api.service.ts

import {Injectable} from '@angular/core';
import {Http,Response} from '@angular/http';


 @Injectable()
 export class DataApi {


 private url = 'http://ukopuz.com/api/2'; 

 constructor(private http:Http){
 }

  getReferenceData(){
    return new Promise(resolve =>{
     this.http.get(`${this.url}`) 
    .subscribe(res => resolve(res.json()))
  });
 }

}

的reference.html

  <ion-content class="content">

    <ion-grid>
      <ion-row *ngFor="let ref of reference">
         <ion-col col-4 >
           <img src="http://ukopuz.com/{{ref}}" >
         </ion-col>
     </ion-row>
   </ion-grid>

</ion-content>

reference.ts

 import { Component } from '@angular/core';
 import { IonicPage, NavController, NavParams,ModalController } from 
'ionic-angular';
 import {DataApi} from '../../app/dataapi/data-api.service';
 import {Http, HttpModule} from '@angular/http';
 import {ModalPage} from '../modal/modal';

 @IonicPage()
 @Component({
  selector: 'page-references',
  templateUrl: 'references.html',
  })
  export class ReferencesPage {

  reference : any;
  constructor(public navCtrl: NavController, public navParams: 
  NavParams,public dataApi:DataApi,
   public http:HttpModule,public modalCtrl:ModalController) {
  }

  ionViewDidLoad() {
   console.log('ionViewDidLoad ReferencesPage');
    this.dataApi.getReferenceData().then(data =>
     this.reference = data);
      console.log("data:"+ this.reference );
     console.log("viewload");
}


 }  

data.json

[
 {
   "3": "/img/ref/adana.png",
   "4": "/img/ref/ajans.png",
   "5": "/img/ref/akp.jpg",
   "6": "/img/ref/akp.png",
   "7": "/img/ref/akpgenclik.png",
   "8": "/img/ref/ankara.png",
   "9": "/img/ref/arnavut.png",
   "10": "/img/ref/aydin.png"
   }
 ]

1 个答案:

答案 0 :(得分:0)

我已经从API检查了你的返回json,它没有返回任何数据,因为你在.html页面得到任何回复

检查API页面