首页 > 解决方案 > 如何显示最后一个索引输入值标签... ng-repeat

问题描述

如何在 ng-repeat 的最后一个索引中显示输入值,但它显示每个行项目...我只想要最后一个索引用户输入付款金额请任何人帮助我,非常感谢

<table class="table display  table-hover table-bordered product-overview mb-10" id="support_table">
    <thead>
        <tr class="bg-info">
            <th class="col-md-4">Shirka Name</th>
            <th class="col-md-1">Approvals</th>
            <th class="col-md-2">CompanyRate</th>
            <th class="col-md-1">Mofa Upload Date</th>
            <th class="col-md-2">Payment</th>
            <th class="col-md-1">Balance</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="item in VisaPaymentList">
            <td>{{item.ShirkaName}}</td>
            <td>{{item.approvals}}</td>
            <td>{{item.CompanyRate}}</td>
            <td>{{item.DateField}}</td>
            <td><input ng-change="BalanceMinus()"
                       ng-model="item.PaymentReceived" autocomplete="off" 
                       id="payment" class="form-control input-height" 
                       placeholder="Payment" type="text">
            </td>
            <td>{{item.Balance}}</td>
        </tr>

    </tbody>
</table>

标签: angularjsangularjs-directiveangularjs-ng-repeat

解决方案


ng-if指令与项目范围的$last属性一起使用:ng-repeat

    <tr ng-repeat="item in VisaPaymentList">
        <td>{{item.ShirkaName}}</td>
        <td>{{item.approvals}}</td>
        <td>{{item.CompanyRate}}</td>
        <td>{{item.DateField}}</td>
        <td>    
            <̶i̶n̶p̶u̶t̶ ̶n̶g̶-̶c̶h̶a̶n̶g̶e̶=̶"̶B̶a̶l̶a̶n̶c̶e̶M̶i̶n̶u̶s̶(̶)̶"̶
            <input ng-if="$last" ng-change="BalanceMinus()"
                   ng-model="item.PaymentReceived" autocomplete="off" 
                   ̶i̶d̶=̶"̶p̶a̶y̶m̶e̶n̶t̶"̶ ̶c̶l̶a̶s̶s̶=̶"̶f̶o̶r̶m̶-̶c̶o̶n̶t̶r̶o̶l̶ ̶i̶n̶p̶u̶t̶-̶h̶e̶i̶g̶h̶t̶"̶ ̶
                   name="payment" class="form-control input-height" 
                   placeholder="Payment" type="text">
        </td>
        <td>{{item.Balance}}</td>
    </tr>

$lasttrue时,<input>将添加元素。否则<td>元素将为空。

有关详细信息,请参阅


推荐阅读