angularjs - Is it possible to delete an item by taking one of the item in array using javascript? -


i have used angular material modal window confirm delete item ng-repeat created items, don't want delete item index, need delete of id.

$scope.users = [{   _id:'1',   firstname: 'obi-wan',   lastname: 'kenobi'  }, {   _id:'2',   firstname: 'boba',   lastname: 'fett'  }, {   _id:'3',   firstname: 'han',   lastname: 'solo' }]; 

i have used _id here, of id, need delete particular item.
plunker of deleting item of index. need of _id. can please me.
plunker here

so have user object in yout delete function shown in code can delete object using splice method , send delete request can use $http service below.

$scope.delete= function(user){                $http.delete('/users/' + user._id, {params: {userid: user._id}})                       .then(function (response) {                       if(response.status == 200){                          var index = $scope.users.indexof(user);                          $scope.users.splice(index, 1);                       }                }) }; 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -