0

I am getting the following error while trying to set the DB value using Angular.js.

Error:

TypeError: index.push is not a function

I am explaining my code below.

<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',$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 " >
<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" ng-keypress="clearField('comment');"></td>
</tr>

When user is selecting the value from first drop down list the below part is executing.

$scope.removeBorder=function(id,index,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){
            //console.log('sub',response.data);
            angular.forEach(response.data,function(obj){
                var data={'name':obj.subcat_name,'value':obj.subcat_id};
                $scope.listOfSubCatagory+index.push(data);
            })
        },function errorCallback(response) {
        })
    }

I am getting error at this $scope.listOfSubCatagory+index.push(data); line.Please help me to resolve this error.

1 Answer 1

0

You are using ng-change="removeBorder('catagory',$index,catagory.value);"

where $index returns the index of element in the list , which is an integer .

You are trying to call .push() function on an integer that's why you are getting this error .

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

7 Comments

i need to make $scope.listOfSubCatagory+index to $scope.listOfSubCatagory0,$scope.listOfSubCatagory1..etc..
for that you can try $scope['listOfSubCatagory' + index] , it will create a key in $scope which can be accessed as $scope.listOfSubCatagory0 ... etc.
@ p2: I did as per you but same error came in same line.
don't do index.push() , index is an integer , there is no push function for an integer . push function works for array objects . I don't have your code so i am not able to debug your problem properly . Try to work on index.push() part .
I have already given the code .Please check my post view part is already there.
|

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.