I need one help.I need to set some value into array after index is changing using Angular.js.I am explaining my code below.
<tr ng-repeat="d in days">
<td>{{d.day_name}}</td>
<td> <select class="form-control" id="catagory" ng-model="catagory" ng-options="cat.name for cat in listOfCatagory track by cat.value " ng-change="removeBorder('catagory',$index,catagory.value);">
</select></td>
<td>
<select class="form-control" id="subcatagory[$index]" ng-model="subcatagory[$index]" ng-options="sub.name for sub in listOfSubCatagory[$index] track by sub.value " ng-change="setSubCatagory($index,subcatagory[$index].value);">
<option value="">Select Subcategory</option>
</select>
</td>
<td><input type="text" name="comment" id="comment" class="form-control oditek-form" placeholder="Add Comment" ng-model="comment[$index]" ng-keyup="comment($index,comment[$index]);"></td>
</tr>
<input type="button" class="btn btn-success" ng-click="saveResturantDetails(billdata);" id="saveData" value="Save" style="margin-right:20px;"/>
I am collecting each row data like below.
var rowData = {};
$scope.removeBorder = function(id, index, catvalue) {
$scope.listOfSubCatagory[index] = [];
var catdata = $.param({
'action': 'subcat',
'cat_id': catvalue
});
$http({
method: 'POST',
url: "php/customerInfo.php",
data: catdata,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function successCallback(response) {
angular.forEach(response.data, function(obj) {
var data = {
'name': obj.subcat_name,
'value': obj.subcat_id
};
$scope.listOfSubCatagory[index].push(data);
})
}, function errorCallback(response) {})
rowData['cat'] = catvalue;
}
$scope.setSubCatagory = function(index, subcatvalue) {
rowData['subcat'] = subcatvalue;
console.log('sub cat', rowData);
}
$scope.comment = function(index, comment) {
rowData['comment'] = comment;
}
Here i need to push all row selected value into a array in row wise.Please help me.
Create 3 string objects var Category, var SubCategory and var Comment.
On Save function push the three variables to Rowdata array:
rowData.push({Cat:Category, SubCat:SubCategory , Comment:Comment});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.