I need to delete and item from a list (that is populated from an array) using and ActionSheet (trigger by an on-hold event) instead of the standard ng-click.
The problem is that I can't figure out how to pass the index numbre or the item id to locate it and delete it.
Here is the HTML:
<ion-list>
<ion-item ng-repeat="mensaje in mensajes" class="item" ng-click="abrirMensaje()"
on-hold="mostrarMenu(mensaje)">
<h2>{{ mensaje.alert }}</h2>
<p>{{ mensaje.hid }}</p>
</ion-item>
</ion-list>
And here is the controller for the ActionSheet:
$scope.mostrarMenu = function(mensaje) {
// Show the action sheet
var hideSheet = $ionicActionSheet.show({
buttons: [
{ text: '<b>Compartir</b>' },
],
destructiveText: '<b>Eliminar</b>',
cancelText: '<b>Cancelar</b>',
cancel: function() {
},
buttonClicked: function(index) {
return true;
},
destructiveButtonClicked: function(mensaje) {
return true;
}
});
};
Any ideas?
I see that you are using an ng-repeat there so you can pass the index easily with $index
<ion-list>
<ion-item ng-repeat="mensaje in mensajes" class="item" ng-click="abrirMensaje()"
on-hold="mostrarMenu(mensaje, $index)">
<h2>{{ mensaje.alert }}</h2>
<p>{{ mensaje.hid }}</p>
</ion-item>
</ion-list>