首页 > 解决方案 > 无法使用 ngfor ANGULAR 在 html 中获取值

问题描述

我有一个数组,它存储了所有这些数据

Form values: {
  "employees": [
    {
      "firstName": "R",
      "lastName": "B",
      "repeat_sun": true,
      "repeat_mon": true,
      "repeat_tue": false,
      "skills": [
        {
          "skill": "JAVA",
          "exp": "2"
        }
      ],
      "userdays": [
        "Sun",
        "Mon"
      ]
    }
  ]
}

我已将这些值存储在 tempArray 中,并在我的 html 中访问它

模板

<table class="table table-bordered">
    <thead>
        <tr>
            <th scope="col">first name</th>
            <th scope="col">last name</th>
            <th scope="col">skill and exp</th>
            <th scope="col">days</th>
        </tr>
    </thead>
    <tbody>
        <tr
       *ngFor="let details of tempArray"
                id="{{ details.empIndex }}">
            <td> {{ details.firstName }}</td>
            <td>{{ details.lastName }}</td>
            <td>  <span *ngFor="let data of details.skills">
                    {{ data.skill }} and {{ data.exp }},
                    <br />
                  </span>
            </td>

            <td> <span *ngFor="let data of details.userdays">
                    {{ details.userdays}}
                    <br />
                  </span>
           </td>
        </tr>
</tbody>
</table>

我能够显示所有值,但是 userdays...我需要显示 userdays vals

https://stackblitz.com/edit/angular-hdfeqs

标签: angular

解决方案


在此处输入图像描述

这就是您的阵列的保存方式。您的阵列上没有用户日。用户日保存为平面。


推荐阅读