I have a json object in angular
[
{
"orderNumber": 5821784,
"accountNumber": 167067702,
"taskCodes": {
"3": 1,
"5": 1,
"23": 1,
"51": 1,
"71": 1
},
"orderCode": "TC",
"orderState": 0
},
{
"orderNumber": 5821785,
"accountNumber": 167067703,
"taskCodes": {
"23": 1,
"41": 1,
"51": 1
},
"orderCode": "TC",
"orderState": 0
}
]
i need to update, delete and add new taskCodes in taskCodes list.
Here is my html code :-
<table class="table table-bordered">
<thead>
<tr>
<th>Code</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="(key, taskCode) in Obj.taskCodes">
<td>
<span data-ng-hide="editMode[$index]">{{key}}</span>
<input type="text" class="input-sm form-control" data-ng-model="key" data-ng-show="editMode[$index]">
</td>
<td>
<span data-ng-hide="editMode[$index]"> {{taskCode}} </span>
<input type="number" class="input-sm form-control" data-ng-model="taskCode" data-ng-show="editMode[$index]" >
</td>
<td><span class="glyphicon glyphicon-edit accordion-toggle clickable" data-ng-hide="editMode[$index]" data-ng-click="edit($index)"></span>
<span class="glyphicon glyphicon-ok accordion-toggle clickable" data-ng-hide="!editMode[$index]" data-ng-click="addItem($index)"></span>
</td>
</tr>
</tbody>
</table>
Controller Edit function :-
$scope.items = [];
$scope.addItem = function () {
//Need code here
}
$scope.editMode=[];
$scope.edit = function(index) {
$scope.editMode[index] = true;
};
Can someone please help me to do all that. Thanks in advance
if (!(Object.prototype.toString.call($scope.items) === '[object Array]')) { $scope.items = []; }As a first operation.