Open In App

Angular PrimeNG Dock Properties

Last Updated : 26 Dec, 2022
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. It provides a lot of templates, components, theme design, an extensive icon library, and much more. In this article, we will see the Angular PrimeNG Dock Properties.

The Dock component in Angular PrimeNG is a navigation component that acts as a menu item & it resembles the dock menu in Ubuntu OS or Mac OS. The Dock menu item is built on MenuItem of PrimeNG and provides many functionalities. The Dock properties allow us to modify the component with the help of properties and provide great extensibility quickly.

Angular PrimeNG Dock Properties:

  • id(string): It is the unique identifier of the element.
  • styleClass(string): It is the style class of the element.
  • style(object): It is the inline style of the element.
  • model(object): The MenuModel instance defines the action items.
  • position(string): It is the position of the element. The default value is the bottom.

 

Syntax:

<p-dock [model]="..." position="...">
  <ng-template pTemplate="item" let-item>
    <img [src]="item.icon" 
        [alt]="item.label" 
        width="100%" />
  </ng-template>
</p-dock>

Creating Angular application & Module Installation:

Step 1: Create an Angular application using the following command.

ng new geeks_angular

Step 2: After creating your project folder i.e. geeks_angular, move to it using the following command.

cd geeks_angular

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: The project structure 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 the Angular PrimeNG Dock Properties. In the following example, we have a Dock in the left direction.

  • app.component.html:

HTML




<h1 style="color: green; text-align: center;">
    GeeksforGeeks
</h1>
<h3>Angular PrimeNG Dock Properties</h3>
  
<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>


  • app.component.ts:

Javascript




import { Component } from "@angular/core";
import { MessageService } from "primeng/api";
import { PrimeNGConfig, MenuItem } from "primeng/api";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.css"],
    providers: [MessageService]
})
  
export class AppComponent {
    dockItems: MenuItem[];
    constructor(
        private messageService: MessageService,
        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 { FormsModule } from "@angular/forms";
import { BrowserAnimationsModule } 
    from "@angular/platform-browser/animations";
import { DockModule } from "primeng/dock";
import { AppComponent } from "./app.component";
import { RippleModule } from "primeng/ripple";
import { ImageModule } from "primeng/image";
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        RippleModule,
        FormsModule,
        ImageModule,
        DockModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule {}


Output:

 

Example 2: Below is another example code that illustrates the use of the Angular PrimeNG Dock Properties. In the following example, we have modified the model data using the command in MenuModel.

  • app.component.html:

HTML




<h1 style="color: green; text-align: center;">
    GeeksforGeeks
</h1>
<h3>Angular PrimeNG Dock Properties</h3>
  
<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>


  • app.component.ts:

Javascript




import { Component } from "@angular/core";
import { MessageService } from "primeng/api";
import { PrimeNGConfig, MenuItem } from "primeng/api";
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.css"],
    providers: [MessageService]
})
export class AppComponent {
    dockItems: MenuItem[];
    constructor(
        private messageService: MessageService,
        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:
                command: () => {
                    this.dockItems = [...this.dockItems, this.dockItems[0]];
                }
            }
        ];
    }
}
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 { FormsModule } from "@angular/forms";
import { BrowserAnimationsModule } 
    from "@angular/platform-browser/animations";
import { DockModule } from "primeng/dock";
import { AppComponent } from "./app.component";
import { RippleModule } from "primeng/ripple";
import { ImageModule } from "primeng/image";
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        RippleModule,
        FormsModule,
        ImageModule,
        DockModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule {}


Output:

 

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



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

Similar Reads