Open In App

Angular PrimeNG Toolbar Templates

Last Updated : 15 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • start: This is used to place the elements at the start of the Toolbar component.
  • center: This is used to place the elements at the center of the Toolbar component.
  • end: This is used to place the elements at the end of the Toolbar component.

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.

  • app.component.html:

HTML




<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>


  • 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 { 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.

  • app.component.html:

HTML




<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>


  • 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 { 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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads