ionic Popover


$ionicPopover

$ionicPopover is a view box that can float above the app content.

It can implement the following features:

  • Display more information on the current page.
  • Select some tools or configurations.
  • Provide a list of actions on the page.

Methods

fromTemplate(templateString, options)
或
fromTemplateUrl(templateUrl, options)

Parameter description:

templateString: Template string.

templateUrl: The template URL to load.

options: Initialization options.

Example

HTML Code Part

<p> <button ng-click="openPopover($event)">Open Popover</button> </p> <script id="my-popover.html" type="text/ng-template"> <ion-popover-view> <ion-header-bar> <h1 class="title">My Popover Title</h1> </ion-header-bar> <ion-content> Hello! </ion-content> </ion-popover-view> </script>

fromTemplateUrl Method

angular.module('ionicApp', ['ionic']) .controller( 'AppCtrl',['$scope','$ionicPopover','$timeout',function($scope,$ionicPopover,$timeout){ $scope.popover = $ionicPopover.fromTemplateUrl('my-popover.html', { scope: $scope }); //.fromTemplateUrl() Method $ionicPopover.fromTemplateUrl('my-popover.html', { scope: $scope }).then(function(popover) { $scope.popover = popover; }); $scope.openPopover = function($event) { $scope.popover.show($event); }; $scope.closePopover = function() { $scope.popover.hide(); }; //Remove Popover $scope.$on('$destroy', function() { $scope.popover.remove(); }); //Execute after hiding the popover $scope.$on('popover.hidden', function() { //Execute code }); //Execute after removing the popover $scope.$on('popover.removed', function() { //Execute code }); }])

Try it »

We can also treat the template as a string and use the .fromTemplate() method to implement the popover:

fromTemplate Method

angular.module('ionicApp', ['ionic']) .controller( 'AppCtrl',['$scope','$ionicPopover','$timeout',function($scope,$ionicPopover,$timeout){ $scope.popover = $ionicPopover.fromTemplateUrl('my-popover.html', { scope: $scope }); //.fromTemplate() Method var template = '<ion-popover-view><ion-header-bar> <h1 class="title">My Popover Title</h1> </ion-header-bar> <ion-content> Hello! </ion-content></ion-popover-view>'; $scope.popover = $ionicPopover.fromTemplate(template, { scope: $scope }); $scope.openPopover = function($event) { $scope.popover.show($event); }; $scope.closePopover = function() { $scope.popover.hide(); }; //Remove Popover $scope.$on('$destroy', function() { $scope.popover.remove(); }); //Execute after hiding the popover $scope.$on('popover.hidden', function() { //Execute code }); //Execute after removing the popover $scope.$on('popover.removed', function() { //Execute code }); }])

Try it »
Other Extensions