AngularJS .destroy() shows console error, but works? -
i use destroy() function this:
$scope.cities[i].destroy(); then when use app works fine, console says:
$scope.cities[i] undefined however without it, doesn't work. should ignore error?
more code
$scope.somefunction= function (id) { (var = 0; < $scope.cities.length; i++) { if ($scope.cities[i] == id) { $scope.splicecities(i); $scope.cities[i].destroy(); } } $scope.splicecities = function(i) { $scope.cities.splice(i, 1); }; } function called on ng-click on country.
splice mutates array, i index points element when calling destroy(). if i pointed last element before splice, error. fortunately splice returns elements spliced out array, try this:
$scope.somefunction = function (id) { (var = 0; < $scope.cities.length; i++) { if ($scope.cities[i].id == id) { var spliced = $scope.cities.splice(i, 1); spliced[0].destroy(); break; } } }
Comments
Post a Comment