I have a simple form which has two text boxes, the values typed into the boxes are displayed in a div using angularJS. I also have a button which adds a new row of two text boxes to the form using jQuery, this also gives them their ng-model.
However these new text boxes don't work for assigning the values to the div. Is there a way that I can dynamically add more rows to this table and have them work?
HTML:
<table>
<tr>
<td><input type="text" ng-model="value1a"></td>
<td><input type="text" ng-model="value1b"></td>
</tr>
</table>
<input type="button" value="Add Row" name="addRow">
<div>
<p>{{value1a}} {{value1b}}</p>
</div>
jquery:
$(document).ready(function() {
var count = 2;
$('[name="addRow"]').click(function() {
$('.table tr:last').after('<tr></tr>');
$('.table tr:last').append('<td><input type="text" ng-model="value' + count + 'a"></td>');
$('.table tr:last').append('<td><input type="text" ng-model="value' + count + 'b"></td>');
$('.div').append('<p>{{value' + count + 'a}} {{value' + count +'b}}</p>');
count++;
});
});
I know the reason is probably because the ng-model needed to be available from the start of the page load for it to work, but how can I add new rows like this?