Messages is used to display alerts inline.
import { MessagesModule } from 'primeng/messages';
A single message is specified by Message interface in PrimeNG that defines the id, severity, summary and detail as the properties. Messages to display can either be defined using the value property which should an array of Message instances or using a MessageService are defined using the value property which should an array of Message instances.
<p-messages
[(value)]="messages"
[enableService]="false"
[closable]="false" />
The severity option specifies the type of the message.
<p-messages [(value)]="messages" [enableService]="false" />
A binding to the value property is required to provide messages to the component.
<p-button
type="button"
pRipple
(onClick)="addMessages()"
label="Show"
styleClass="mr-2" />
<p-button
type="button"
pRipple
(onClick)="clearMessages()"
label="Clear"
severity="secondary" />
<p-messages [(value)]="messages" [enableService]="false" />
Messages are closable by default resulting in a close icon being displayed on top right corner. In order to disable closable messages, set closable to false. Note that in this case two-way binding is not necessary as the component does not need to update its value.
<p-messages [(value)]="messages" [closable]="false" />
MessageService alternative does not require a value binding to an array. In order to use this service, import the class and define it as a provider in a component higher up in the component tree such as application instance itself so that descandant components can have it injected. If there are multiple message components having the same message service, you may use key property of the component to match the key of the message to implement scoping.
<div class="flex justify-content-center gap-2">
<p-button (onClick)="addSingle()" label="Show Single" />
<p-button severity="success" (onClick)="addMultiple()" label="Show Multiple" />
<p-button severity="secondary" (onClick)="clear()" label="Clear All" />
</div>
<p-messages />
Alternative way to provide the content for the messages is templating. In this case value property and message service is ignored and only static is displayed.
<p-messages severity="info">
<ng-template pTemplate>
<img src="https://primefaces.org/cdn/primeng/images/primeng.svg" width="32" />
<div class="ml-2">Always bet on Prime.</div>
</ng-template>
</p-messages>
Transition of the open and hide animations can be customized using the showTransitionOptions and hideTransitionOptions properties, example below disables the animations altogether.
<p-messages
[(value)]="messages"
[showTransitionOptions]="'500ms'"
[hideTransitionOptions]="'500ms'"
[enableService]="false" />
Following is the list of structural style classes, for theming classes visit theming page.
Name | Element |
---|---|
p-messages | Container element. |
p-message | Message element. |
p-message-info | Message element when displaying info messages. |
p-message-warn | Message element when displaying warning messages. |
p-message-error | Message element when displaying error messages. |
p-message-success | Message element when displaying success messages. |
p-message-close | Close button. |
p-message-close-icon | Close icon. |
p-message-icon | Severity icon. |
p-message-summary | Summary of a message. |
p-message-detail | Detail of a message. |
Following is the list of structural style classes, for theming classes visit theming page.
Name | Element |
---|---|
p-inline-message | Message element. |
p-inline-message-info | Message element when displaying info messages. |
p-inline-message-warn | Message element when displaying warning messages. |
p-inline-message-error | Message element when displaying error messages. |
p-inline-message-success | Message element when displaying success messages. |
p-inline-message-icon | Severity icon. |
p-inline-message-text | Text of a message. |
Message components use alert role that implicitly defines aria-live as "assertive" and aria-atomic as "true". Since any attribute is passed to the root element, attributes like aria-labelledby and aria-label can optionally be used as well.
Close element is a button with an aria-label that refers to the aria.close property of the locale API by default.
Key | Function |
---|---|
enter | Closes the message. |
space | Closes the message. |
API defines helper props, events and others for the PrimeNG Messages module.
Messages is used to display alerts inline.
Defines the input properties of the component.
Defines emit that determine the behavior of the component based on a given condition or report the actions that the component takes.
Defines the templates used by the component.
No description available
Defines the input properties of the component.
Defines the custom interfaces used by the module.
Deines valid options for the message.
Defines the service used by the component
Methods used in service.