Open In App

Angular PrimeNG Toolbar Templates

Angular PrimeNG is a framework used with angular to create components with great styling this framework is very easy to use and is used to make responsive websites. In this article, we will know how to use the Toolbar Templates in Angular PrimeNG.

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



This article will show Toolbar Templating in Angular PrimeNG. The templates are used to put some content on some pre-structured containers. 

Toolbar templates are discussed below:



Creating Angular Application And Installing 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

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 Templates using the left Template.




<h1 style="color: green">GeeksforGeeks</h1>
<h4>Angular PrimeNG Toolbar Templates</h4>
 
<p-toolbar>
    <div class="p-toolbar-group-left">
        <p-button label="GfG Tutorials"
            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>




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'
            }
        ];
    }
}




import { NgModule } from '@angular/core';
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: [
        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 Templates using both left and right Templates.




<h1 style="color: green">GeeksforGeeks</h1>
<h4>Angular PrimeNG Toolbar Templates</h4>
 
<p-toolbar>
    <div class="p-toolbar-group-left">
      <p-button
          label="GfG Tutorials"
          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">
        <span class="p-input-icon-left">
            <i class="pi pi-search"></i>
            <input type="text"
                placeholder="Search here geek..."
                pInputText />
        </span>
        <p-button label="Search"
            styleClass="p-button-success"></p-button>
    </div>
</p-toolbar>




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'
            }
        ];
    }
}




import { NgModule } from '@angular/core';
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: [
        BrowserAnimationsModule,
        ToolbarModule,
        ButtonModule,
        SplitButtonModule,
    ],
    declarations: [ AppComponent ],
    bootstrap:    [ AppComponent ]
})
 
export class AppModule { }

Output:

 

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


Article Tags :