I have a popover in my Ionic framework app with to options: share and delete. I need to display a confirmation popup when the delete option is chosen, but I don't know how.
How can this be done? Do I need to create a separate controller for the popover? I already did a popup comming from a ActionSheet but this is somehow different.
This is the controller:
$ionicPopover.fromTemplateUrl('templates/popover.html', {
scope: $scope
}).then(function(popover) {
$scope.popover = popover;
});
// Triggered on a button click, or some other target
$scope.openPopover = function($event) {
$scope.popover.show($event);
};
And this is the popover template:
<ion-popover-view style="height: 120px">
<ion-content>
<div class="list">
<a class="item">
Compartir
</a>
<a class="item">
Eliminar
</a>
</div>
</ion-content>
</ion-popover-view>
The ionic popover is a small overlay of content that is used to display on top of the current page to show secondary information. The ion ic popover component is similar to tooltips; it is a pop-up dialog box where users can interact by an element.
Ionic - JavaScript Popup. This service is used for creating a popup window on top of the regular view, which will be used for interaction with the users. There are four types of popups namely − show, confirm, alert and prompt.
With Ionic 6, styling modals and popovers has changed slightly because you can’t easily access all properties anymore as they are converted to use Shadow DOM now! But good news, you can still inject styling through the defined CSS variables or Shadow parts.
ion-popovercan be used by writing the component directly in your template. This reduces the number of handlers you need to wire up in order to present the popover. When using ion-popoverwith Angular, React, or Vue, the component you pass in will be destroyed when the popover is dismissed.
You can place an ng-click
on your delete (or Eliminar in your template, I think?)
<ion-popover-view style="height: 120px">
<ion-content>
<div class="list">
<a class="item">
Compartir
</a>
<a class="item" ng-click="showConfirm()">
Eliminar
</a>
</div>
</ion-content>
</ion-popover-view>
$ionicPopover.fromTemplateUrl('templates/popover.html', {
scope: $scope
}).then(function(popover) {
$scope.popover = popover;
});
// Triggered on a button click, or some other target
$scope.openPopover = function($event) {
$scope.popover.show($event);
};
$scope.showConfirm = function() {
var confirmPopup = $ionicPopup.confirm({
title: 'Are you sure?',
template: 'Are you sure you want to delete?'
});
confirmPopup.then(function(res) {
if(res) {
console.log('You are sure');
} else {
console.log('You are not sure');
}
});
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With