Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display an Ionic popup from a popover option?

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>
like image 238
David Prieto Avatar asked Apr 27 '15 21:04

David Prieto


People also ask

What is an ionic popover?

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.

What is the use of pop up in ionic?

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.

How to style modals and popovers in ionic 6?

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.

How do I use ion-popover?

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.


1 Answers

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');
     }
   });
 };
like image 51
David says Reinstate Monica Avatar answered Sep 30 '22 10:09

David says Reinstate Monica