* ngFor不与动态值工作 [英] *ngFor is not working with dynamic values

查看:669
本文介绍了* ngFor不与动态值工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

工作的一些阵列项目,但憋屈地步* ngFor我以前不接受他人提供的动态值 * ngFor

Working on some array projects but Stuck on point where *ngFor did't accept dynamic value provided by another *ngFor.

<table border="2">
  <tr>
    <th rowspan="2">Subject</th>
    <th colspan="4" *ngFor='#category of json.category_name'>{{category}}</th>
    <th colspan="4">Overall</th>
  </tr>
  <tr>
    <div *ngFor="#category of json.category_name">
      <th *ngFor="#fa of json.total_fa.category">{{fa}}</th>  //Not Working
    </div>
  </tr>
</table> 

在这里的注释行,我想提供 json.total_fa.category 其中本类别从另一个即将到来 * ngFor 这是略高于声明。但得到没有任何结果似乎角度尝试找出 json.total_fa.category 本身,这是不是present。

here in the commented line i want to provide json.total_fa.category where this category is coming from another *ngFor which is declared just above. but getting no result it seems angular try to find out json.total_fa.category itself which is not present.

但我想加载 json.total_fa_term1 (这是第一个指数分类)。我怎么能achive这一点。

but i want to load json.total_fa_term1 (which is first index from the category). how can i achive this.

我可以使用一个以上的* ngFor上相同的HTML组件?

  1. Can i use more than one *ngFor on same HTML component ?

有时* ngFor和* ngIf不能正常工作,而在相同的元素嵌入为什么?

sometimes *ngFor and *ngIf is not working properly while embed on the same element why ?

这是我的 workground演示

推荐答案

您需要使用 .total_fa【类别】而不是 .total_fa的。类别否则你会尝试用名称来访问属性类别

You need to use .total_fa[category] instead of .total_fa.category otherwise you will try to access a property with name category:

<div *ngFor="#category of json.category_name">
  <th *ngFor="#fa of json.total_fa[category]">{{fa}}</th>
</div>

查看更新plunkr: http://plnkr.co/edit/v08AdzNsR4GHMlZWQNsR? p = preVIEW

See the updated plunkr: http://plnkr.co/edit/v08AdzNsR4GHMlZWQNsR?p=preview.

这篇关于* ngFor不与动态值工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆