خرید بک لینک

Vote count: 0

Hi i am getting the following error while selecting data using angular.js.

Error:

angularjs.js:107 TypeError: Caot set property '0' of undefined
    at n.$scope.removeBorder (adminCustomerNewController.js:55)
    at fn (eval at <anonymous> (angularjs.js:212), <anonymous>:4:617)
    at n.$eval (angularjs.js:132)
    at angularjs.js:251
    at angularjs.js:263
    at m (angularjs.js:7)
    at $$writeModelToScope (angularjs.js:263)
    at angularjs.js:263
    at g (angularjs.js:261)
    at f (angularjs.js:261)

My code is given below.

<tr ng-repeat="d in days">
        <td>{{d.day_name}}</td>
        <td>
          <table>
            <tbody>
              <tr ng-repeat="answer in d.answers">
                <td>
                  <select class="form-control" id="answer_{{$index}}_{{$parent.$index}}_category" name="answer_{{$index}}_category" ng-model="answer.catagory" ng-options="cat.name for cat in listOfCatagory track by cat.value" ng-change="removeBorder($index,answer.catagory.value,$parent.$index);">
                    <option value="">Select Category</option>
                  </select>
                </td>
                 </tr>
            </tbody>
          </table>
          </td>
          <td>
          <table>
            <tbody>
              <tr ng-repeat="answer in d.answers">
                <td>
                  <select class="form-control" id="answer_{{$index}}_{{$parent.$index}}_subcategory" name="answer_{{$index}}_subcategory" ng-model="answer.subcatagory" ng-options="sub.name for sub in listOfSubCatagory[$index][$parent.index] track by sub.value">
                    <option value="">Select Subcategory</option>
                  </select>
                </td>
                </tr>
            </tbody>
          </table>
          </td>
          <td>
          <table>
            <tbody>
              <tr ng-repeat="answer in d.answers">
                <td>
                  <input type="text" id="answer_{{$index}}_{{$parent.$index}}_comment" name="answer_{{$index}}_comment" placeholder="Add Comment" ng-model="answers.comment">
                </td>

          </tr>
            </tbody>
          </table>
          </td>
          <td>
          <table>
            <tbody>
              <tr ng-repeat="answer in d.answers">
                <td>
                    <input type="submit" name="plus" id="plus" value="+" style="width:20px; text-align:center;" ng-click="addNewRow(d.answers, true)">
                    <div ng-show="$first && !$last">
                     <input type="submit" name="minus" id="minus" value="-" style="width:20px; text-align:center;" ng-click="removeRow(d.answers, $last)">
                     </div>
                </td>
          </tr>
            </tbody>
          </table>
          </td>
              </tr>
            </tbody>
          </table>
        </td>
      </tr>

My controller side code is given below.

$scope.listOfSubCatagory = []; 
  $scope.removeBorder=function(index,catvalue,parent){
      console.log('ind',index,catvalue,parent);
     // $scope.listOfSubCatagory
    $scope.listOfSubCatagory[index][parent]=[];
     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+parent].push(data);
            })
        },function errorCallback(response) {
        }) 
  }
});

I am getting error in this $scope.listOfSubCatagory[index][parent]=[]; please help me to resolve this error.

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: جمعه 28 اسفند 1394 ساعت: 12:59

صفحه بندی