-
Couldn't load subscription status.
- Fork 0
Alerts
Chris Carson edited this page Sep 8, 2017
·
5 revisions
Use the nzbAlert selector with native Bootstrap alert markup. This creates an instance of NzbAlertDirective, with an API that closely follows the native Bootstrap implementation. Notes:
- Bootstrap removes the alert markup when the modal is closed. The library does not change this behavior,
but it does provide an
openmethod that reinserts the original markup into the DOM — showing the alert again. - Relatedly, you can hide the alert when it is instantiated using the
initiallyOpeninput.
<div nzbAlert #alert1="nzbAlert" class="alert alert-warning alert-dismissible fade" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong>Holy guacamole!</strong> You should check in on some of those fields below.
</div>
<p>Alert 1 Status: {{ alert1.status | async }}</p>Use ViewChild to grab the instance in your component:
export class SomeComponent implements AfterViewInit {
@ViewChild('alert1') alert1: NzbAlertDirective;
ngAfterViewInit() {
console.log(this.alert1);
}
}-
initiallyOpen: boolean = trueWhether to show the alert initially. Use[initiallyOpen]="false"to hide the alert. - Use the contextual classes (e.g.
alert-warning) as you would normally. - Add the
fadeclass to enable animation. - Add the
alert-dismissableclass if you include a close button.
-
close(): voidA wrapper around the native method. Within the modal, you can usedata-dismiss="alert"as well. Note that Bootstrap removes the markup from the DOM when the alert is closed; we do not change this behavior. -
open(): voidReinserts the alert markup (if necessary) and shows the alert.
-
status: Observable<string>One of:- 'uninitialized'
- 'opening'
- 'opened'
- 'closing'
- 'closed'
-
events: Observable<Event>Provides the native bootstrap alert events (close.bs.alertandclosed.bs.alert) as an observable. Note that there are no analogousopenandopenedevents, since such events do not exist natively.