0

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.
}

1 Answer 1

1

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...

Sign up to request clarification or add additional context in comments.

2 Comments

sir,i have little bit confusion how to collected the selected group of data .Can you please share your idea here.
ng-model attaches the value of the input/select to a value on the scope, so I suppose you have variables called "comment" (an array), "catagory" and "subcatagory" (another array). If you doesn't have one of those, angular will create these in your scope. They all are available as properties of $scope in your controller. Please try console.log($scope) inside your saveResturantDetails to understand what is happening...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.