Angular2 嵌套了 ngFor。可以嵌套表达式吗?

Angular2 nested ngFor. Is nested expressions possible?

我正在尝试在表达式绑定中使用一个值。我知道这是无效的,但想知道类似的事情是否可行。如果不行,有没有别的方法可以解决。

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

@Component({
selector: 'Home',
templateUrl: './views/home/home.html'
})
export class HomeComponent implements OnInit{

    rows = [
       { 'FirstName': 'John', 'LastName': 'Doe' },
       { 'FirstName': 'Ashley', 'LastName': 'Doe' }
    ];

    cols = [
       { 'Desc': 'First Name', 'Data': 'FirstName' },
       { 'Desc': 'Last Name', 'Data': 'LastName' }
    ]; 
}

home.html

<table>
  <thead>
    <tr>
      <th *ngFor="let col of cols">{{col.Desc}}</th>
    </tr>
  </thead>
  <tr *ngFor="let row of rows">     
    <td *ngFor="let col of cols">
      {{row.{{col.Data}}}}     
    </td>
  </tr>
</table>

这样使用:

{{ row[col.Data] }}

在 Javascript 中,您也可以通过 obj.propNameobj[propName] 访问每个 属性!