0

I cannot fetch the selected data from table using AngularJS.

Here is my code:

<tr ng-repeat="d in days">
    <td>{{d.day}}</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');"></select>
    </td>
    <td>
        <select class="form-control"  id="subcatagory" ng-model="subcatagory" ng-options="sub.name for sub in listOfSubCatagory track by sub.value"></select>
    </td>
    <td>
        <input type="text" name="comment" id="comment" class="form-control oditek-form" placeholder="Add Comment" ng-model="comment" ng-keypress="clearField('comment');">
    </td>
</tr>   

Here I need when I will select value from first selection field the value should fetch and according the same row second selection field will fill up not other row.

$scope.removeBorder = function(){
    $scope.listOfSubCatagory = null;
    $scope.listOfSubCatagory = [];
    var catdata = $.param({
        'action': 'subcat',
        'cat_id': $scope.catagory.value
    });
    $http({
        method: 'POST',
        url: "php/customerInfo.php",
        data: catdata,
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    }).then(function successCallback(response){
        console.log('sub', response.data);
        angular.forEach(response.data, function(obj) {
            var data = {
                'name': obj.subcat_name,
                'value':obj.subcat_id
            };
            $scope.listOfSubCatagory.push(data);
        })
    }, function errorCallback(response) { })
}

Here I am getting the category value as null.

halfer
  • 19,824
  • 17
  • 99
  • 186
satya
  • 3,508
  • 11
  • 50
  • 130
  • `ng-repeat` creates a child scope. Your `ng-model` primitives are only available in each child scope and parent is unaware of them – charlietfl Feb 24 '16 at 14:37
  • See: http://stackoverflow.com/questions/17606936/angularjs-dot-in-ng-model – Jack A. Feb 24 '16 at 14:44

0 Answers0