Angular PrimeNG Messages Animation Configuration
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. It provides a lot of templates, components, theme design, an extensive icon library, and much more. In this article, we will see the Angular PrimeNG Messages Animation Configuration.
The Messages component is used to display alerts inline. They are used to provide alerts to users within the webpage only providing a smoother experience and replacing the default alerts. The Messages Animation Configuration allows configuring the default animation.
Messages Animation Configuration properties:
- showTransitionOptions: Here we put the animation displayed when we show a message. The default value is 300ms ease-out.
- hideTransitionOptions: Here we put the animation displayed when we hide a message. Â The default value is 200ms cubic-bezier(0.86, 0, 0.07, 1).
Â
Syntax:
<p-messages
[showTransitionOptions]="'..."
[hideTransitionOptions]="'...'">
</p-messages>
Creating Angular application & Module Installation:
Step 1: Create an Angular application using the following command.
ng new geeks_angular
Step 2: After creating your project folder i.e. geeks_angular, move to it using the following command.
cd geeks_angular
Step 3: Install PrimeNG in your given directory.
npm install primeng --save
npm install primeicons --save
Project Structure: The project structure will look like the following:
Â
Steps to run the above file: Run the below command
ng serve --save
Example 1: Below is the example code that illustrates the use of Messages Animation Configuration in Angular PrimeNG. In the following example, we have a different animation when the message appears.
HTML
< h1 style = "color: green; text-align: center;" >
GeeksforGeeks
</ h1 >
< h3 >Angular PrimeNG Messages Animation Configuration</ h3 >
< button
type = "button"
pButton
(click)="showViaService()"
label = "Add Message" >
</ button >
< p-messages
[showTransitionOptions]="'1s ease-in-out'"
[hideTransitionOptions]="'0.5s linear'">
</ p-messages >
|
Javascript
import { Component } from "@angular/core" ;
import { Message, MessageService } from "primeng/api" ;
import { PrimeNGConfig } from "primeng/api" ;
@Component({
selector: "app-root" ,
templateUrl: "./app.component.html" ,
providers: [MessageService]
})
export class AppComponent {
msgs1: Message[];
msgs2: Message[];
constructor(
private messageService: MessageService,
private primengConfig: PrimeNGConfig
) {}
ngOnInit() {
this .primengConfig.ripple = true ;
}
showViaService() {
this .messageService.add({
severity: "success" ,
summary: "Service Message" ,
detail: "Via MessageService"
});
}
}
|
Javascript
import { NgModule } from "@angular/core" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { FormsModule } from "@angular/forms" ;
import { HttpClientModule } from "@angular/common/http" ;
import { BrowserAnimationsModule }
from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import { MessagesModule } from "primeng/messages" ;
import { MessageModule } from "primeng/message" ;
import { ButtonModule } from "primeng/button" ;
import { InputTextModule } from "primeng/inputtext" ;
import { RippleModule } from "primeng/ripple" ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
MessagesModule,
MessageModule,
ButtonModule,
InputTextModule,
RippleModule,
FormsModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
|
Output:
Â
Example 2: Below is another example code that illustrates the use of Messages Animation Configuration in Angular PrimeNG. In the following example, we have turned off the animation.
HTML
< h1 style = "color: green; text-align: center;" >
GeeksforGeeks
</ h1 >
< h3 >Angular PrimeNG Messages Animation Configuration</ h3 >
< button
type = "button"
pButton
(click)="showViaService()"
label = "Add Message" >
</ button >
< p-messages
[showTransitionOptions]="'0s'"
[hideTransitionOptions]="'0s'">
</ p-messages >
|
Javascript
import { Component } from "@angular/core" ;
import { Message, MessageService } from "primeng/api" ;
import { PrimeNGConfig } from "primeng/api" ;
@Component({
selector: "app-root" ,
templateUrl: "./app.component.html" ,
providers: [MessageService]
})
export class AppComponent {
msgs1: Message[];
msgs2: Message[];
constructor(
private messageService: MessageService,
private primengConfig: PrimeNGConfig
) {}
ngOnInit() {
this .primengConfig.ripple = true ;
}
showViaService() {
this .messageService.add({
severity: "success" ,
summary: "Service Message" ,
detail: "Via MessageService"
});
}
}
|
Javascript
import { NgModule } from "@angular/core" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { FormsModule } from "@angular/forms" ;
import { HttpClientModule } from "@angular/common/http" ;
import { BrowserAnimationsModule }
from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import { MessagesModule } from "primeng/messages" ;
import { MessageModule } from "primeng/message" ;
import { ButtonModule } from "primeng/button" ;
import { InputTextModule } from "primeng/inputtext" ;
import { RippleModule } from "primeng/ripple" ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
MessagesModule,
MessageModule,
ButtonModule,
InputTextModule,
RippleModule,
FormsModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
|
Output:
Â
Reference: https://primefaces.org/primeng/messages
Last Updated :
26 Dec, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...