简体   繁体   English

如何在Ionic中从JSON打印数据

[英]How to print data from JSON in Ionic

I have created a db in JSON but I can not see the data or get error on the other end but I can se the object in the log. 我已经在JSON中创建了一个数据库,但是在另一端看不到数据或出现错误,但是可以在日志中找到对象。

[    {
      "teachers": [
          {
            "img":"assets/inst/J.png",
            "name":"Janine ",
            "bio":"lorem"
          },{
            "img":"assets/insta/I.png",
            "name":"Itzhak",
            "bio":"lorem"
          }
      ]
    }
]

Service for fetching the data 数据获取服务

    homeds: Home[];
  constructor( public dataService: DataProvider) {
    this.dataService.fetchData().subscribe(
           (data) => {
             this.homeds = data}  
         )
  }

Lastly my template file is 最后我的模板文件是

<ion-row class="home" *ngFor="let home of homeds">
 <img src="{{ home.teachers?.img }}" alt="">
</ion-row>

You should have nested ngFor since teachers is an array 您应该嵌套ngFor因为教师是一个数组

<ion-row class="home" *ngFor="let home of homeds">
 <div   *ngFor="let homeobj of home.teachers ">
   <img src="{{ homeobj?.img }}" alt="">
  </div>
</ion-row>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM