Open In App

Angular PrimeNG Dock Basic

Last Updated : 31 Jan, 2023
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 know how to use Dock Basic in Angular PrimeNG.

The Dock Component in Angular PrimeNG is a navigation component that acts as a menu item. The dock component resembles the dock menu in Ubuntu OS or Mac OS. The Dock menu item is built on MenuItem of PrimeNG and provides many functionalities.

Dock Basic: The Basic dock just contains the Dock menu element with the items inside it.

 

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: Run the below command to see the output

ng serve --save

Example 1: Below is the example code that illustrates the use of Angular PrimeNG Dock Basic with top and bottom doc.

  • app.component.html:

HTML




<h1 style="color: green;"> GeeksforGeeks</h1>
<h3>Angular PrimeNG Dock Basic</h3>
  
<div class="dock-window">
    <p-dock [model]="dockItems" position="top">
        <ng-template pTemplate="item" let-item>
            <img [src]="item.icon" 
                 [alt]="item.label" 
                 width="100%">
        </ng-template>
    </p-dock>
  
    <p-dock [model]="dockItems" position="bottom">
        <ng-template pTemplate="item" let-item>
            <img [src]="item.icon" 
                 [alt]="item.label" 
                 width="100%">
        </ng-template>
    </p-dock>
</div>


  • app.component.ts:

Javascript




import { Component } from '@angular/core';
import { PrimeNGConfig, MenuItem } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
  
export class AppComponent {
    dockItems: MenuItem[];
    constructor(
        private primengConfig: PrimeNGConfig
    ) { }
  
    ngOnInit() {
        this.primengConfig.ripple = true;
        this.dockItems = [
            {
                label: 'GfgLogo 1',
                icon:
            },
            {
                label: 'GfgLogo 2',
                icon:
            },
            {
                label: 'GfgLogo 3',
                icon:
            },
            {
                label: 'GfgLogo 4',
                icon:
            },
        ];
    }
}
  
export interface Tutorial {
    title?: string;
    category?: string;
    rating?: number;
}


  • app.module.ts:

Javascript




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


Output:

 

Example 2: Below is another example code that illustrates the use of Angular PrimeNG Dock Basic with left and right doc.

  • app.component.html:

HTML




<div style="text-align: center">
    <h1 style="color: green;"> GeeksforGeeks</h1>
    <h3>Angular PrimeNG Dock Basic</h3>
</div>
  
<div class="dock-window">
    <p-dock [model]="dockItems" position="left">
        <ng-template pTemplate="item" let-item>
            <img [src]="item.icon" 
                 [alt]="item.label" 
                 width="100%">
        </ng-template>
    </p-dock>
  
    <p-dock [model]="dockItems" position="right">
        <ng-template pTemplate="item" let-item>
            <img [src]="item.icon" 
                 [alt]="item.label" 
                 width="100%">
        </ng-template>
    </p-dock>
</div>


  • app.component.ts:

Javascript




import { Component } from '@angular/core';
import { PrimeNGConfig, MenuItem } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
  
export class AppComponent {
    dockItems: MenuItem[];
    constructor(
        private primengConfig: PrimeNGConfig
    ) { }
  
    ngOnInit() {
        this.primengConfig.ripple = true;
        this.dockItems = [
            {
                label: 'GfgLogo 1',
                icon:
            },
            {
                label: 'GfgLogo 2',
                icon:
            },
            {
                label: 'GfgLogo 3',
                icon:
            },
            {
                label: 'GfgLogo 4',
                icon:
            },
        ];
    }
}
  
export interface Tutorial {
    title?: string;
    category?: string;
    rating?: number;
}


  • app.module.ts:

Javascript




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


Output:

 

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



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

Similar Reads