ionic Popover
$ionicPopover
$ionicPopover is a view box that can float over the app's content.
It can achieve the following functions:
- Display more information on the current page.
- Select some tools or configurations.
- Provide a list of actions on the page.
Method
fromTemplate(templateString, options)
或
fromTemplateUrl(templateUrl, options)
Parameter Description:
templateString: template string.
templateUrl: the URL of the template to load.
options: initialization options.
Example
HTML code section
<p>
<button ng-click="openPopover($event)">Open the 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
(
)
;
}
;
//
Dismiss the 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 create 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
=
'
My Popover Title
'
; $
scope
.
popover
= $
ionicPopover
.
fromTemplate
(
template
,
{
scope
: $
scope
}
)
; $
scope
.
openPopover
=
function
(
$
event
)
{
$
scope
.
popover
.
show
(
$
event
)
;
}
; $
scope
.
closePopover
=
function
(
)
{
$
scope
.
popover
.
hide
(
)
;
}
;
//
Dismiss the 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 »