Open In App

Angular PrimeNG Dock Advanced

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 the Dock Advanced 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.



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 Advanced using the tooltips.




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




import { Component } from '@angular/core';
import { MenuItem } from 'primeng/api';
import { MessageService } from "primeng/api";
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    providers: [MessageService]
})
  
export class AppComponent {
    geeks: MenuItem[];
  
    ngOnInit() {
        this.geeks = [
            {
                label: 'GfgLogo 1',
                tooltipOptions: {
                    tooltipLabel: "Gfg Logo 1",
                    tooltipPosition: 'bottom',
                    positionLeft: 15,
                    positionTop: -15
                },
                icon:
            },
            {
                label: 'GfgLogo 2',
                tooltipOptions: {
                    tooltipLabel: "Gfg Logo 2",
                    tooltipPosition: 'bottom',
                    positionLeft: 15,
                    positionTop: -15
                },
                icon:
            },
            {
                label: 'GfgLogo 3',
                tooltipOptions: {
                    tooltipLabel: "Gfg Logo 3",
                    tooltipPosition: 'bottom',
                    positionLeft: 15,
                    positionTop: -15
                },
                icon:
            },
            {
                label: 'GfgLogo 4',
                tooltipOptions: {
                    tooltipLabel: "Gfg Logo 4",
                    tooltipPosition: 'bottom',
                    positionLeft: 15,
                    positionTop: -15
                },
                icon:
            },
        ];
    }
}




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 Advanced using the tooltips and menubar.




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




import { Component } from '@angular/core';
import { MenuItem } from 'primeng/api';
import { MessageService } from "primeng/api";
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    providers: [MessageService]
})
  
export class AppComponent {
    geeks: MenuItem[];
    gfg: MenuItem[];
  
    ngOnInit() {
          
        this.gfg = [
            {
                label: 'HTML',
                items: [
                    {
                        label: 'HTML 1'
                    },
                    {
                        label: 'HTML 2'
                    }
                ]
            },
            {
                label: 'Angular',
                items: [
                    {
                        label: 'Angular 1'
                    },
                    {
                        label: 'Angular 2'
                    }
                ]
            }
        ];
  
        this.geeks = [
            {
                label: 'GfgLogo 1',
                tooltipOptions: {
                    tooltipLabel: "Gfg Logo 1",
                    tooltipPosition: 'bottom',
                    positionLeft: 15,
                    positionTop: -15
                },
                icon:
            },
            {
                label: 'GfgLogo 2',
                tooltipOptions: {
                    tooltipLabel: "Gfg Logo 2",
                    tooltipPosition: 'bottom',
                    positionLeft: 15,
                    positionTop: -15
                },
                icon:
            },
            {
                label: 'GfgLogo 3',
                tooltipOptions: {
                    tooltipLabel: "Gfg Logo 3",
                    tooltipPosition: 'bottom',
                    positionLeft: 15,
                    positionTop: -15
                },
                icon:
            },
            {
                label: 'GfgLogo 4',
                tooltipOptions: {
                    tooltipLabel: "Gfg Logo 4",
                    tooltipPosition: 'bottom',
                    positionLeft: 15,
                    positionTop: -15
                },
                icon:
            },
        ];
    }
}




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

Output:

 

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


Article Tags :