Open In App

Angular PrimeNG Form TreeSelect Styling

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

Angular PrimeNG is an open-source library that consists 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 be seeing the Angular PrimeNG Form TreeSelect Styling.

The TreeSelect Component allows the users to select items from hierarchical data. It accepts an array of TreeNodes as its options property to show the data.

Angular PrimeNG Form TreeSelect Styling: This component helps to make the interactive TreeSelect by implementing the different stylings provided by Angular PrimeNG. These styling components are described below

  • p-treeselect: It is a container element.
  • p-treeselect-label-container: Label container used to display particular goods.
  • p-treeselect-label: It is a label to show the chosen items.
  • p-treeselect-trigger: It is the dropdown button.
  • p-treeselect-panel: It is the items overlay panel.
  • p-treeselect-items-wrapper: It is a list of the things.

 

Syntax:

<p-treeSelect 
    [(ngModel)]="..."
    selectionMode="..." 
    display="..."
    [options]="..." 
    placeholder="...">
</p-treeSelect>

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: In this article, we will learn about Form TreeSelect Styling in Angular PrimeNG.

  • app.component.html:

HTML




<div style="width:80%">
    <h1 style="color:green">GeeksforGeeks</h1>
    <h2 >Angular PrimeNG Form TreeSelect Styling</h2>
    <p-treeSelect
        [(ngModel)]="selected"
        selectionMode="single"
        [options]="nodes"
        placeholder="Select a Node"
        >
    </p-treeSelect>
</div>


  • app.component.ts:

Javascript




import { Component } from "@angular/core";
import { TreeNode } from "primeng/api";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls:["./app.component.css"]
})
  
export class AppComponent {
    nodes: TreeNode[] = [];
    selected: any;
    ngOnInit()
    {
        this.nodes = [
            {
                "label": "Work",
                "icon": "pi pi-folder",
                  
            },
            {
                "label": "Home",
                "icon": "pi pi-folder",
                  
            },
            {
                "label": "Multimedia",
                "icon": "pi pi-folder",
                  
            }
        ];
    }
}


  • app.component.css
     

CSS




:host ::ng-deep .p-treeselect .p-treeselect-label-container{
   background:red !important;
   color:white !important;
   font-weight:bold !important
 }


  • app.module.ts:

Javascript




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


Output:

 

Example 2: This is another example of Form TreeSelect Styling in Angular PrimeNG. Here we will style background of the options

  • app.component.html:

HTML




<div style="width:80%">
    <h1 style="color:green">GeeksforGeeks</h1>
    <h2 >Angular PrimeNG Form TreeSelect Styling</h2>
    <p-treeSelect
        [(ngModel)]="selected"
        selectionMode="single"
        [options]="nodes"
        placeholder="Select a Node"
        >
    </p-treeSelect>
</div>


  • app.component.ts:

Javascript




import { Component } from "@angular/core";
import { TreeNode } from "primeng/api";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls:["./app.component.css"]
})
  
export class AppComponent {
    nodes: TreeNode[] = [];
    selected: any;
    ngOnInit()
    {
        this.nodes = [
            {
                "label": "Work",
                "icon": "pi pi-folder",
                  
            },
            {
                "label": "Home",
                "icon": "pi pi-folder",
                  
            },
            {
                "label": "Multimedia",
                "icon": "pi pi-folder",
                  
            }
        ];
    }
}


  • app.component.css
     

CSS




:host ::ng-deep  .p-tree{
   background:red !important;
   color:white !important;
   font-weight:bold !important
 }


  • app.module.ts:

Javascript




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


Output:

 

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



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

Similar Reads