Angular4:连接字符串以在模板中形成动态键

时间:2017-06-30 15:09:32

标签: angular templates variables key concatenation

我正在尝试从* ngFor索引中动态创建模板内的键。

<div *ngFor="let col of table; let i = index">
  <span *ngFor="let row of col; let j = index">
    {{ row.ricj }}
  </span>
</div>

其中“ricj”中的“i”和“j”实际上是指数“i”和“j”。这可能吗?

原始表对象是以这种方式构建的,

makeTable(){
    for(this.c = 0; this.c < this.columnslength; this.c++){
      for(this.r = 0; this.r < this.rowslength; this.r++){
        this.key = "r" + this.r + "c" + this.c;
        this.cell = { [this.key]: this.key };
        this.cols.push(this.cell);
      }
      this.table.push(this.cols);
      this.cols = [];
  }
}

表对象看起来像这样,

[
   {
      [{ "r0c0": "r0c0" }, { "r1c0": "r1c0" }]
   },
   {
      [{ "r0c1": "r0c1" }, { "r1c1": "r1c1" }]
   }
]

1 个答案:

答案 0 :(得分:3)

试试这个,

  <div *ngFor="let col of table; let i = index">
    <span *ngFor="let row of col; let j = index">
        {{ row['r' + j + 'c' + i] }}
    </span>
  </div>