私は請求書の Web サイトに取り組んでおり、ng-repeat のどこにでも新しい行を追加できるようにしたいと考えています。
サイト: http://completeinvoice.com/
HTML
<tr id="row-{{$index+1}}" class="item-row" ng-repeat="item in invoice.items">
<td class="col-span2">@Html.TextBoxFor(m => m.InvoiceColOneDetails, new { id = "cel1-row{{$index+1}}", @class = "invoiceColOneDetails", @placeholder = "{{$index+1}}" })</td>
<td class="col-span6">
<textarea id="cel2-{{$index+1}}" class="invoiceColTwoDetails" ng-model="item.description" auto-grow></textarea>
</td>
<td class="col-span1">@Html.TextBoxFor(m => m.InvoiceColThreeDetails, new { id = "cel3-row{{$index+1}}", @class = "invoiceColThreeDetails text-center", @placeholder = "0", @ng_model = "item.hrsQty" })</td>
<td class="col-span1">@Html.TextBoxFor(m => m.InvoiceColFourDetails, new { id = "cel4-row{{$index+1}}", @class = "invoiceColFourDetails text-center", @placeholder = "0", @ng_model = "item.ratePrice" })</td>
<td class="col-span2 relative disabled-field">@Html.TextBoxFor(m => m.InvoiceColFiveDetails, new { id = "cel5-row{{$index+1}}", @class = "invoiceColFiveDetails text-right", @placeholder = "0", @Value = "{{rowTotal(item) | currency}}", @disabled = "disabled" })</td>
<td class="no-border disabled-field remove-row">
<a href="javascript:void(0)" class="remove-item tooltip-right" title="Delete row (Ctrl+Delete)" ng-click="deleteRow($index)">
<i class="icon-remove-sign"></i>
</a>
<a href="javascript:void(0)" class="remove-item tooltip-right" title="Insert new row" ng-click="insertRow($index)">
<i class="icon-add-sign"></i>
</a>
</td>
</tr>
Angularjs
$scope.insertRow = function (index) {
$scope.invoice.items.push({
description: null,
hrsQty: null,
ratePrice: null
});
};
これにより、ng-repeat の下部に新しい行が追加されます。ng-repeat のどこかに新しい行を追加することさえ可能ですか? 私はこれを理解するのに苦労しています。