Reputation: 11794
Getting my head around the ng-table grid. Stuck at the point how to add a new row:
$scope.addRow = function(add) {
$scope.data.push(add)
$scope.showAdd = false;
};
Trying to add the new object to the data array but does not work? what is wrong here?
html:
<table class="noborder">
<tr>
<td rowspan="2">ID: {{add.id}}<input type="hidden" name="id" value="{{add.id}}"></td>
<td>Firstname:</td>
<td><input type="text" name="fn" class="w100" ng-model="add.fn"></td>
<td>Description: </td>
<td>Email:</td>
<td><input type="text" name="em" class="w180" ng-model="add.em"></td>
<td><input type="button" value=" save " ng-click="addRow(p);"></td>
</tr>
<tr>
<td>Lastname:</td>
<td><input type="text" name="ln" class="w100" ng-model="add.ln"></td>
<td><input type="text" name="dc" class="w180" ng-model="add.dc"></td>
<td>Phone: </td>
<td><input type="text" name="ph" class="w120" ng-model="add.ph"></td>
<td><input type="button" value=" cancel" ng-click="cancelEdit()"></td>
</tr>
</table>
Here is a plunkr ref: http://plnkr.co/edit/9woANV?p=preview
Upvotes: 2
Views: 3432
Reputation: 340
In addRow.html you are adding variable 'p' which always evaluates as null. Change this to 'add'.
e.g.
ng-click="addRow(add);"
plunkr: https://plnkr.co/edit/xEL78EZNGrD6GxE029X8?p=preview
Upvotes: 0