Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show ionicPopover by default

How to show ionicPopover by default, don't click or any other event. Once the page or the view loaded, show the popover?

cmr.controller('JoinMeeting', function($scope, $ionicPopover) {
    $ionicPopover.fromTemplateUrl('joinMrTips.html', {
    scope: $scope,
}).then(function(popover) {
    $scope.popover = popover;
});

$scope.$on('$viewContentLoaded',function(){
    $scope.popover.show();
});

})
like image 945
user3117414 Avatar asked Oct 31 '14 07:10

user3117414


People also ask

How do you use popover in ionic?

To present a popover, call the present method on a popover instance. In order to position the popover relative to the element clicked, a click event needs to be passed into the options of the present method. If the event is not passed, the popover will be positioned in the center of the viewport.

Which element is used for creating popover in ionic?

Popover Controller. It is responsible for creating popover in the Ionic application. It uses create() method for creating popover. You can customize the controller by setting popover options in the create method.

How many ways can you add the popover in ionic framework?

There are two ways to use ion-popover : inline or via the popoverController .


3 Answers

You were very close. According to the official documentation of IonicPopover, The syntax of popover.show() is as follows :

show($event) where The $event or target element which the popover should align itself next to

Hence, rewriting your code as follows will do the job :

$scope.$on('$viewContentLoaded',function(){
    $scope.popover.show(".class-of-host-control-of-popup");
});

Complete Example, along with code --> here

like image 82
Manish Kr. Shukla Avatar answered Oct 17 '22 23:10

Manish Kr. Shukla


This works without having to include jQuery:

$scope.$on('$viewContentLoaded',function(){
  $scope.popover.show(angular.element(document.querySelector('.class-of-host-control-of-popup')));
});
like image 45
BartBiczBoży Avatar answered Oct 17 '22 22:10

BartBiczBoży


An exemple which uses Ionic "utils" classes (here, DomUtil):

    var nodeClass = 'target-host-item-class';
    var evtTarget = $event.target;
    var hostNode = ionic.DomUtil.getParentOrSelfWithClass(evtTarget, nodeClass);

    $ionicPopover.fromTemplateUrl('popover-template.html', {
        scope: $scope
    }).then(function(popover) {
        popover.show(hostNode);
    });

Not really worse or better than other answers. Simply avoids using direct DOM queries or jQuery.

Here, I want the popover to always be aligned with the item using the class .target-host-item-class.

like image 29
VinceOPS Avatar answered Oct 17 '22 22:10

VinceOPS