【问题标题】:Angular2 how to display an array of numbers [closed]Angular2如何显示数字数组[关闭]
【发布时间】:2017-08-13 06:15:04
【问题描述】:

什么是 angular2 中最优雅的解决方案,用于在 x 行和 y 列中显示 z 数字的 html 表?

X、Y 和 Z 是数字,不一定是集合。该表还应包含数字 1 到 z。

【问题讨论】:

    标签: html angular


    【解决方案1】:

    我会这样做:Plunker

    组件

    rows : any[];
    cols : any[];
    
    constructor() { 
      this.rows = Array(50).fill('');
      this.cols = Array(10).fill('');
    }
    

    模板:

    <table>
      <tr *ngFor="let row of rows; let rowId = index">
        <td *ngFor="let col of cols; let colId = index">{{rowId + colId*10+1}}</td>
      </tr>
    </table>
    

    【讨论】:

    • 如果行和列是数字,这将如何工作。我有一个包含 500 个数字的表格,我希望显示一个 10 x 50 的表格
    • @Shakur 按照上面的编辑操作。
    • 我们如何打印 1 到 500 :) 这么简单的东西对我来说 angular2 一点也不直观
    • @Shakur 通过添加索引! (就像编辑一样)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-22
    • 2015-12-24
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 2017-02-15
    • 1970-01-01
    相关资源
    最近更新 更多