无法显示Ionic * ngfor的数据

时间:2018-02-17 21:15:51

标签: php typescript ionic-framework

您好我在使用Ionic应用程序在html文件上返回数据时遇到问题。我使用auth-service.ts提供程序连接到数据库,结果在console->上返回正常。网络 - > XHR(friendsNewsFeed)

On ionic serve我收到错误 尝试diff [object Object]只允许数组和iterables

https://forum.ionicframework.com/t/problem-with-ngfor/121590

home.ts

      import { Component, ViewChild } from "@angular/core";
      import { NavController, App, AlertController } from "ionic-angular";
      import { AuthService } from "../../providers/auth-service";
      import { Common } from "../../providers/common";
      import { Camera, CameraOptions } from "@ionic-native/camera";
      @Component({ selector: "page-home", templateUrl: "home.html" })


      export class HomePage {
public photos: any;
public base64Image: string;
public fileImage: string;
public userDetails: any;
public resposeData: any;
public dataSet: any;
public noRecords: boolean;
userPostData = {
    uid: "",
    token: "",
    created: "",
    message: ""
};
constructor(
    public authService: AuthService
) {
    const data = JSON.parse(localStorage.getItem("userData"));
    this.userDetails = data.userData;
    this.userPostData.uid = this.userDetails.uid;
    this.userPostData.token = this.userDetails.token;
    this.userPostData.created = "";
    this.noRecords = false
    this.getFeed();
}
ngOnInit() {
    this.dataSet = [];
}   
getFeed() {
    this.common.presentLoading();
    this.authService.postData(this.userPostData, "userNewsFeed").then(
        result => {
            this.resposeData = result;
            if (this.resposeData) {
                this.common.closeLoading();
                this.dataSet = this.resposeData;
                console.log(this.dataSet);

            } else {
                console.log("No access");
            }
        },
        err => {
            //Connection failed message
        }
    );
}

home.html的

       <ion-card *ngFor="let item of dataSet; let msgIndex = index">
      <ion-item>
      <ion-card-content>
      <p [innerHTML]="item.message | linky"></p>
      </ion-card-content>
      </ion-item>
      </ion-card>

AUTH-service.ts

        import { Injectable } from '@angular/core';
        import { Http, Headers } from '@angular/http';
        import 'rxjs/add/operator/map';

        let apiUrl = "http://localhost/PHP-Slim-Restful1/api/";
        //let apiUrl = 'https://api.thewallscript.com/restful/';
        /*
          Generated class for the AuthService provider.

          See https://angular.io/docs/ts/latest/guide/dependency-injection.html
          for more info on providers and Angular 2 DI.
        */
        @Injectable()
        export class AuthService {

          constructor(public http: Http) {
            console.log('Hello AuthService Provider');
          }

          postData(credentials, type){

            return new Promise((resolve, reject) =>{
              let headers = new Headers();
              this.http.post(apiUrl+type, JSON.stringify(credentials), {headers: headers}).
              subscribe(res =>{
                resolve(res.json());
              }, (err) =>{
                reject(err);
              });

            });

          }

        }

任何提示?

0 个答案:

没有答案