Angular PrimeNG Button Label
Angular PrimeNG is a UI component library for Angular Applications. It offers many pre-built themes and UI components for a variety of tasks like inputs, menus, charts, Buttons, etc. In this article, we will be seeing Angular PrimeNG Button Label.
A Button component is used for carrying out some action when clicked. The label property of the button component is used to set the text of the button.
Angular PrimeNG Button Label Properties:
- label: The label property is used to set the text of the button.
- icon: This property of the button component is used to set the icon for the button. It can be used with or without the label property.
Syntax:
<button pButton type="button" label="..." > </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: 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:
Example 1: This example shows the use of the label property to set the text of the button.
app.component.html
< div class = "header" > < h2 >w3wiki</ h2 > < h3 >Angular PrimeNG Button Label</ h3 > </ div > < div class = "buttons" > < button pButton type = "button" label = "Label for First Button" > </ button > < button pButton type = "button" label = "Label for Second Button" > </ button > </ div > |
app.component.css
div{ display : flex; align-items: center ; justify- content : center ; flex- direction : column; } .header h 2 { 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 { } |
Run the below command to see the output.
ng serve --open
Output:
Example 2: The label property can also be used with the icon property. This example shows the use of the label property with the icon property.
app.component.html
< div class = "header" > < h2 >w3wiki</ h2 > < h3 >Angular PrimeNG Button Label</ h3 > </ div > < div class = "buttons" > < button pButton type = "button" icon = "pi pi-check" label = "Label with left Icon" iconPos = "left" > </ button > < button pButton type = "button" icon = "pi pi-check" label = "Label with right Icon" iconPos = "right" > </ button > </ div > |
app.component.css
div{ display : flex; align-items: center ; justify- content : center ; flex- direction : column; } .header h 2 { 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