简体   繁体   English

如何在angular中使用ngFor绑定数据

[英]How to bind data with ngFor in angular

I am new to angular.我是角度的新手。 Just learning it.只是学习它。 I want to bind data with ngFor.我想用 ngFor 绑定数据。 but its not showing any data.但它没有显示任何数据。 Kindly help me to solve this请帮我解决这个问题

html file : html文件:

 <tbody class="text-center">
          <tr *ngFor="let agent of agentlist ;let i = index">
              <td>{{i + 1 + paginationObject?.page * paginationObject?.itemPerPage}}</td>-->
              <td>{{agent?.id?agent?.id:''}}</td>
          </tr>
        </tbody>

error : <!--bindings={ "ng-reflect-ng-for-of": null }-->错误: <!--bindings={ "ng-reflect-ng-for-of": null }-->

Try removing the --> at the end of the first table cell and correct the binding on the second one.尝试删除第一个表格单元格末尾的-->并更正第二个表格单元格上的绑定。

<tbody class="text-center">
  <tr *ngFor="let agent of agentlist ;let i = index">
      <td>{{i + 1 + paginationObject?.page * paginationObject?.itemPerPage}}</td>-->
      <td>{{agent?.id}}</td>
  </tr>
</tbody>

Also, you need to make sure that agentlist has something to iterate.此外,您需要确保agentlist有一些要迭代的内容。 maybe putting a console.log(agentlist) and see what it has inside of it in the ts class.也许放一个console.log(agentlist)并查看它在 ts 类中的内容。 If angelist is only declared but never defined you will get that error.如果angelist只被声明但从未定义,你会得到那个错误。 Initialize angelist as an empty array to make sure that have an iterable before defining with the final data.angelist初始化为一个空数组,以确保在使用最终数据定义之前具有可迭代对象。

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

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