在Angular2模板中显示数组 [英] Display array in Angular2 template

查看:103
本文介绍了在Angular2模板中显示数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的angular2组件的@Input(): data类型为[number,number].数组的大小应根据输入确定.现在我该如何将该数组的内容绑定到html中的表,即该表应该是这样的:

My angular2 component has an @Input(): data of type [number,number]. The size of the array is should be determined from the input. How can I now bind the content of this array to a table in html, i.e., the table should be something like this:

<table>
    <tr>
        <td> data[0,0] </td>
        <td> data[0,1] </td>
        ...
    </tr>
    <tr>
        <td> data[1,0] </td>
        <td> data[1,1] </td>
        ...
    </tr>
    ...
</table>

推荐答案

您可以使用两个* ngFor-Directives来做到这一点:

You can do this with two *ngFor-Directives:

<table>
    <tr *ngFor="let row of data">
        <td *ngFor="let value of row">{{value}}</td>
    </tr>
</table>

工作 Plunkr

这篇关于在Angular2模板中显示数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆