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();
});
})
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.
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.
There are two ways to use ion-popover : inline or via the popoverController .
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
This works without having to include jQuery:
$scope.$on('$viewContentLoaded',function(){
$scope.popover.show(angular.element(document.querySelector('.class-of-host-control-of-popup')));
});
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
.
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