Vahid Alvandi Vahid Alvandi - 24 days ago 6
AngularJS Question

how i can remove item from multiple array in angularjs

i have function to remove item in multiple array angularjs. i use a factory like bellow

app.factory("array_obj", function () {
var currentUserIDs = {};
currentUserIDs.data = [];
currentUserIDs.city = [];
return currentUserIDs;

});


in controller have a function like this

$scope.deleteItem = function (index) {
currentUserIDs.city.splice(index, 1);
setUserID(); //insert data in url realtime
}


this work just for one array like city

i need a function to delete any item in array_obj

Answer

function simpleController($scope) {
    $scope.data = { 
       "results1": [ { "id": 1, "name": "Test" }, { "id": 2, "name": "Beispiel" }, { "id": 3, "name": "Sample" } ] ,
       

"results2": [ { "id": 1, "name": "Test2" }, { "id": 2, "name": "Beispiel2" }, { "id": 3, "name": "Sample2" } ] 

}
    ;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<html ng-app>
    
    <body ng-controller="simpleController">
      <div data-ng-repeat="results in data">
           <div data-ng-repeat="result in results">>
             
             {{result.name}}</br>
           </div> 
        </div> 
  
  </body>

</html>

Have Fun..!!!