数组 – 如何使用ngFor Angular 2在对象数组中显示数组

前端之家收集整理的这篇文章主要介绍了数组 – 如何使用ngFor Angular 2在对象数组中显示数组前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要显示位于对象数组中的数组质量.我尝试使用下面的代码在ngFor中调用它.我使用ngFor有什么问题吗?

import { Component} from '@angular/core';

@Component({
    selector: 'my-app',template: `<table>
                  <thead>
                    <tr>
                       <th>Name</th>
                       <th>Quality1</th>
                       <th>Quality2</th>
                    </tr>
                  </thead>
                  <tbody>
                      <tr *ngFor"let item of people">
                         <td>{{item.Name}}</td>
                         <td *ngFor"let item of people.quality">item.quality1</td>
                         <td *ngFor"let item of people.quality">item.quality2/td>
                       </tr>
                  </tbody>
              </table>
   })

  export class AppComponent{    
     people: any = [{Name:"John",quality:[{quality1: "nice",quality2: "humble"}]},{Name:"Dave",quality:[{quality1: "kind",quality2: "caring"}]} ];
  }

截至目前,只有名字出现在表格中,但我也希望质量出现.

解决方法

您可以使用< ng-container>将几个节点与* ngFor组合而不向DOM引入另一个元素:

<ng-container *ngFor"let item of people.quality">
  <td>item.quality1</td>
  <td>item.quality2/td>
</ng-container>

猜你在找的Angularjs相关文章