[AngularJS]Supprimer la ligne sélectionné de la table selon son id

Par hana005, il y a 11 ans


Bonjour,
je dois supprimer la ligne sélectionné de la table en déployant la fonction removeRow,voilà ce que j'ai fais:

<table class="table table-striped table-bordered" style="text-align:center" id="table" > <thead> <th align="center">Référence</th> <th align="center">Nom</th> <th align="center">Prenom</th> <th align="center">Email</th> <th align="center">Adresse Facturation</th> <th align="center" colspan="2">Actions</th> </thead> <tbody> <tr ng-repeat="post in posts" > <td >{{post.id}}</td> <td >{{post.nom}}</td> <td >{{post.prenom}}</td> <td >{{post.email}}</td> <td >{{post.adresse}}</td> <td><a ng-click="deleteController.removeRow(post.id)"> Supprimer</a></td> </tr></tbody> </table>

et le controller ainsi que la fonction removerow(id) qui doit prendre l'id séléctionné en paramètre pour le supprimer(je travaille avec un web service):

.controller('deleteController', ['$scope', '$http' ,function($scope,$http) { $scope.errors = []; $scope.msgs = []; $scope.removeRow = function(id){ $http({method: 'GET', url: 'MyURL/supprimer?id='+$scope.id}).success(function(data, status, headers, config){ if (data.msg != '') { $scope.msgs.push(data.msg); } else { $scope.errors.push(data.error); } }).error(function(data, status) { $scope.errors.push(status); }); };}]);

le problème est que je n'arrive plus à reçevoir l'id et l'envoyer vers la fonction removeRow
merci pour l'aide

2 réponses

workfel, il y a 11 ans

Salut l'erreur viens du fait que ton $scope.id n'existe pas . Il te faut remplacer $scope.id par id

$scope.removeRow = function(id){ $http({method: 'GET', url: 'MyURL/supprimer?id='+id}).success(function(data, status, headers, config){ if (data.msg != '') { $scope.msgs.push(data.msg); } else
hana005, il y a 11 ans

merci kalagan ça marche bien