简体   繁体   中英

How to get value from table using Angular.js?

I need to get value from table according to the row using Angular.js. I am providing my code:

    <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);" >
    <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);"></td>
    </tr>   
 <input type="button" class="btn btn-success" ng-click="saveResturantDetails(billdata);"  id="saveData" value="Save"   style="margin-right:20px;"/>   </div>

From above table I need to fetch the selected value and respective comment field value after click on save button and stored them into a array. Here is my controller side code:

$scope.removeBorder=function(id,index,catvalue){
        $scope.listOfSubCatagory[index]=[];
        rowData['cat']=catvalue;
        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) {
        })
    }
$scope.saveResturantDetails=function(){

   //here i want to collect data.
}

It seems that you're misunderstanding the two-way binding here.

Your data is already collected by ng-model on whatever subcatagory[$index] means. I'm guessing sugcatagory is available on your $scope , so you only have to iterate over the collection...

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM