Skip to content
Related Articles

Related Articles

Angular PrimeNG Button Severity Component

View Discussion
Improve Article
Save Article
  • Last Updated : 12 Aug, 2022
View Discussion
Improve Article
Save Article

Angular PrimeNG is an open-source library that consists of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will be seeing Angular PrimeNG Button Severity Component.

A Button component is used for carrying out some action when clicked. In PrimeNG, different colored buttons are available for different severity levels. There are a total of 6 severity levels: Primary (default), Secondary, Success, Info, Warning, Help, and Danger.

Angular PrimeNG Button Severity Component Properties:

  • label: The label property is used to set the text of the button.

Angular PrimeNG Button Severity Component Styling:

  • p-button-secondary: This class is used to set the severity level of a button to secondary.
  • p-button-success: This class is used to set the severity level of a button to success.
  • p-button-info: This class is used to set the severity level of a button to info.
  • p-button-warning: This class is used to set the severity level of a button to warning.
  • p-button-help: This class is used to set the severity level of a button to help.
  • p-button-danger: This class is used to set the severity level of a button to danger.

Syntax:

<button pButton 
    type="button" 
    label="..." 
    class="...">
</button>

Creating Angular Application and Installing the Module:

Step 1: Create an Angular application using the following command.

ng new appname

Step 2: After creating your project folder i.e. appname, move to it using the following command.

cd appname

Step 3: Finally, Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

The project Structure will look like this after following the above steps:

Project Structure

Run the below command to see the output.

ng serve --open

Example 1: This example shows the use of the Secondary, Success, and info severity buttons.

app.component.html




<div class="header">
    <h2>GeeksforGeeks</h2>
    <h3>
      Angular PrimeNG Button 
      Severity Component
    </h3>
</div>
  
<div class="buttons">
    <button pButton type="button" 
          label="Primary (Default) Button">
    </button>
  
    <button pButton type="button" 
        label="Secondary Button" 
        class="p-button-secondary">
    </button>
  
    <button pButton type="button" 
        label="Success Button" 
        class="p-button-success">
    </button>
  
    <button pButton type="button" 
        label="Info Button" class="p-button-info">
    </button>
</div>

app.component.css




div{
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}
  
.header h2{
    margin-bottom: 0;
    color: green;
}
  
button{
    margin-bottom: 10px;
}

app.component.ts




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
  
export class AppComponent {}

app.module.ts




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import {ButtonModule} from 'primeng/button'
  
@NgModule({
    declarations: [
      AppComponent
    ],
    imports: [
      BrowserModule,
      ButtonModule,
    ],
    providers: [],
    bootstrap: [AppComponent]
})
  
export class AppModule { }

Output:

 

Example 2: This example illustrates the use of the warning, help, and danger severity buttons.

app.component.html




<div class="header">
    <h2>GeeksforGeeks</h2>
    <h3>
      Angular PrimeNG Button 
      Severity Component
    </h3>
</div>
  
<div class="buttons">
    <button pButton type="button" 
        label="Primary (Default) Button">
    </button>
  
    <button pButton type="button" 
        label="Warning Button" 
        class="p-button-warning">
    </button>
  
    <button pButton type="button" 
        label="Help Button" class="p-button-help">
    </button>
  
    <button pButton type="button" 
        label="Danger Button" class="p-button-danger">
    </button>
</div>

app.component.css




div{
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}
  
.header h2{
    margin-bottom: 0;
    color: green;
}
  
button{
    margin-bottom: 10px;
}

app.component.ts




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
  
export class AppComponent {}

app.module.ts




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import {ButtonModule} from 'primeng/button'
  
@NgModule({
    declarations: [
      AppComponent
    ],
    imports: [
      BrowserModule,
      ButtonModule,
    ],
    providers: [],
    bootstrap: [AppComponent]
})
  
export class AppModule { }

Output:

 

Reference: http://primefaces.org/primeng/button


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!