【问题标题】:How to get total row of ngFor loop in html?如何在html中获取ngFor循环的总行?
【发布时间】:2020-11-08 19:12:55
【问题描述】:

如何获取 ngfor 循环的总数,然后显示在中

在上面?

            <p>Total row: "I need to display the number of row here"</p>
           
            <table class="table" >
                <tr>
                    <th>ID</th>
                    <th>Name</th>
                </tr>

                <tr *ngFor="let l of list">
                    <td>{{l.id}}</td>
                    <td>{{l.name}}</td>
                </tr>
            </table>

【问题讨论】:

    标签: html angular web angular9


    【解决方案1】:

    list.length 将给出要显示的总行数

    <p>Total row: "I need to display the number of row here" {{list.length}}</p>
               
                <table class="table" >
                    <tr>
                        <th>ID</th>
                        <th>Name</th>
                    </tr>
    
                    <tr *ngFor="let l of list">
                        <td>{{l.id}}</td>
                        <td>{{l.name}}</td>
                    </tr>
                </table>
    

    【讨论】:

      【解决方案2】:

      列表是一个数组,所以你可以使用长度属性。

      <p>Total row: {{list.length}}</p>
                 
      <table class="table" >
          <tr>
              <th>ID</th>
              <th>Name</th>
          </tr>
      
          <tr *ngFor="let l of list">
              <td>{{l.id}}</td>
              <td>{{l.name}}</td>
          </tr>
      </table>
      

      【讨论】:

        猜你喜欢
        • 2020-08-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-14
        • 2017-06-15
        • 1970-01-01
        相关资源
        最近更新 更多