Binding to Bootstrap alert widget. This binding can be used with virtual elements. Supports custom templates with observables

Examples

Html markup

<div data-bind="alert: { message: message, type: type }"></div>

<div data-bind="alert: { message: 'Using custom alert template', template: 'alertExampleTemplate', type: 'danger' }"></div>

<!-- ko alert: { message: 'Using virtual root element', type: 'success' } -->
<!-- /ko -->

<script type="text/html" id="alertExampleTemplate">
    <p data-bind="text: message"></p>
    <button class="btn btn-primary" data-dismiss="alert">Close</button>
</script>

View model

function AlertExampleViewModel() {
    this.type = ko.observable('info');
    
    this.message = ko.observable('Alert message');
}

Options

All of the options can be observables.

data-bind="alert: { message: message, type: type, template: template, data: data, templateOptions: templateOptions }"