javascript - AngularJS showing error on console, when destroy() called -


so use destroy() delete items $scope.array on click. works fine, when open console following showing:

$scope.array[index].destroy not function 

so delete line of code, in hope fix console error, , did after app not working. checked if else not it's this, working error still showing. have no idea maybe because it's older version?

edit: whole function called on ng-click:

    $scope.spliceitems = function (index)     {             $scope.array.splice(index, 1);         }    $scope.destroyitem = function(index) {              $scope.array[index].destroy();         }      $scope.remove = function(item)     {      (var = 0; < $scope.array.length; i++) {                 if ($scope.array[i].id == item.id) {                         $scope.spliceitems(i);                    $scope.destroyitem(i);          }     } 

edit 2

so, whats problem here? need dynamically multiply function, when adding or removing array:

$scope.gettotal= function() {         var total = 1;         (var = 0; < $scope.array.length; i++) {             total *= $scope.array[i];         }         if (total == 1)             total = 0;         return total;     } 

when use splice doesn't change value of total, multiplies. when use splice + destory() working fine, browser console gives me error reason.

use splice() instead of destroy() e.g.: $scope.array.splice(index, 1);


Comments