Open In App

Angular PrimeNG Toolbar Properties

Improve
Improve
Like Article
Like
Save
Share
Report

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. In this article, we will learn how to use the Toolbar Properties in Angular PrimeNG

The Toolbar Component is used to group buttons and other components. 

Angular PrimeNG Toolbar Properties:

  • style: It is the style of the component.  It is of object data type, the default value is null.
  • styleClass: It is the class of the component. It is of string data type, the default value is null.

 

Creating Angular application & module installation:

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

Project Structure: It will look like the following:

 

Steps to run the application: To run the above file, run the below command:

ng serve --save

Example 1: Below is the example code that illustrates the use of Angular PrimeNG Toolbar Properties.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Toolbar Properties</h5>
  
<p-toolbar>
    <div class="p-toolbar-group-left">
        <p-button label="GfG Turorials" 
            icon="pi pi-book" styleClass="p-button-success">
          </p-button>
        <i class="p-toolbar-separator pi pi-code mr-2"></i>
        <p-splitButton label="GfG Courses" [model]="gfg" 
            styleClass="p-button-warning">
        </p-splitButton>
    </div>
</p-toolbar>


  • app.component.ts:

Javascript




import { Component} from '@angular/core';
import {MenuItem} from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent { 
    gfg: MenuItem[];
      
    ngOnInit() {
        this.gfg = [
            {
                label: 'Data Structure'
            },
            {
                label: 'System Design'
            },
            {
                label: 'SDE Test Series'
            },
            {
                label: 'C++ STL'
            }
        ];
    }
}


  • app.module.ts:

Javascript




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


Output:

 

Example 2: Below is another example code that illustrates the use of Angular PrimeNG Toolbar Properties using both the left and right toolbar groups.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Toolbar Properties</h5>
  
<p-toolbar>
    <div class="p-toolbar-group-left">
        <p-button label="GfG Turorials" icon="pi pi-book" 
            styleClass="p-button-success">
        </p-button>    
        <i class="p-toolbar-separator pi pi-code mr-2"></i>
        <p-splitButton label="GfG Courses" [model]="gfg" 
            styleClass="p-button-warning">
        </p-splitButton>
    </div>
  
    <div class="p-toolbar-group-right">
        <p-button label="Sign In" icon="pi pi-sign-in" 
            style="margin-right: 5px">
        </p-button>
  
        <p-button label="Sign Out" 
            icon="pi pi-sign-out">
          </p-button>
    </div>
</p-toolbar>


  • app.component.ts:

Javascript




import { Component} from '@angular/core';
import {MenuItem} from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
  
export class AppComponent { 
    gfg: MenuItem[];
      
    ngOnInit() {
        this.gfg = [
            {
                label: 'Data Structure'
            },
            {
                label: 'System Design'
            },
            {
                label: 'SDE Test Series'
            },
            {
                label: 'C++ STL'
            }
        ];
    }
}


  • app.module.ts:

Javascript




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


Output:

 

Reference: https://primefaces.org/primeng/toolbar



Last Updated : 02 Nov, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads