Ionic 3错误属性在对象类型上不存在

时间:2019-04-07 21:44:17

标签: angular ionic-framework

当我运行应用程序时,类型'records'上没有显示属性'Object'的错误。 我尝试添加记录:可观察; 但是没有人可以告诉我如何解决这个问题。谢谢

附加.ts.html文件。

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { HospitalPage } from '../hospital/hospital';
import { Observable } from 'rxjs/Observable';
import { HttpClient, HttpHeaders } from '@angular/common/http';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

data: Observable<any>;
records: Observable<any>;
 galleryType = 'regular';
 list: any;

  token: string;


  constructor(public navCtrl: NavController, public httpClient:         
 HttpClient) {

    this.token = "token here ";


  }

  getDataUsingToken(token) { 
         return this.httpClient.get('Url',{headers:new HttpHeaders({
                  'token': token
                 }
               )
             }
          ) 
      }

ngOnInit() { 
    this.getDataUsingToken(this.token).subscribe(data=>{ 
      console.log(data); 
      this.list = data.records;

    },

    err => console.log(err.message)
    );
  } 
}

html文件:

 <ion-item *ngFor="let d of list">
   <div style="font-size: 16px;">{{d.name}}</div>
   <ion-icon name="pin" color="primary"></ion-icon> <font style="font-size: 
      14px;">{{d.city}}</font>
   <ion-icon ios="ios-arrow-forward" md="md-arrow-forward" item-right 
  color="primary" class="pin"></ion-icon>

</ion-item>

1 个答案:

答案 0 :(得分:0)

尝试一下:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { HospitalPage } from '../hospital/hospital';
import { Observable } from 'rxjs/Observable';
import { HttpClient, HttpHeaders } from '@angular/common/http';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

data: Observable<any>;
records: Observable<any>;
 galleryType = 'regular';
 list: any;

  token: string;


  constructor(public navCtrl: NavController, public httpClient:         
 HttpClient) {

    this.token = "token here ";
    this.gettingData(this.token);


  }

  getDataUsingToken(token) { 
         return this.httpClient.get('Url',{headers:new HttpHeaders({
                  'token': token
                 }
               )
             }
          ) 
      }

gettingData(token) { 
    this.getDataUsingToken(token).subscribe(data=>{ 
      console.log(data); 
      this.list = data.records;

    },

    err => console.log(err.message)
    );
  } 
}