Binding to Bootstrap popover. Supports custom templates with observables for popover content
<button class="btn btn-primary" data-bind="popover: {
options: { title: 'Popover with template', placement: 'top' },
template: popoverTemplate,
data: { text: 'First template' }
}">Click</button>
<button class="btn" data-bind="click: switchTemplates">Switch templates</button>
<button class="btn btn-primary" data-bind="popover: {
options: { title: 'Focus', content: 'Focus popover', trigger: 'focus', placement: 'bottom' }
}">Focus</button>
<button class="btn btn-primary" data-bind="popover: {
options: { title: 'Hover', content: 'Hover popover', trigger: 'hover' }
}">Hover</button>
<script type="text/html" id="firstPopoverTemplate">
<button class="close pull-right" type="button" data-dismiss="popover">×</button>
<p data-bind="text: text"></p>
</script>
<script type="text/html" id="secondPopoverTemplate">
<p>Second template</p>
</script>
function PopoverExampleViewModel() {
var self = this;
self.popoverTemplate = ko.observable('firstPopoverTemplate');
self.switchTemplates = function() {
self.popoverTemplate() === 'firstPopoverTemplate'
? self.popoverTemplate('secondPopoverTemplate')
: self.popoverTemplate('firstPopoverTemplate');
};
}
All of the options can be observables, also option's object can be observable too
data-bind="popover: { options: options, template: templateName, data: templateData, templateOptions: templateOptions }"
options
Type: object, can be observable
Bootstrap options for popover. If any option is not specified, uses default value. Please, see Bootstrap documentation
templateName
Type: string, can be observable
Name of template for popover content. If template is not specified, uses content property from options object
templateData
Type: object, can be observable
Data for template
templateOptions
Type: object
Contains options for template.
They are: templateEngine, afterRender, beforeRender and afterAdd.
Please, see Knockout documentation for details.
If you don't need use template, you can use short notation of binding, which uses only option object.
data-bind="popover: popoverOptions"
popoverOptions
Type: object, can be observable
Bootstrap options for popover. If any option is not specified, uses default value. Please, see Bootstrap documentation