Open In App

Angular PrimeNG Form TreeSelect Styling

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

 



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.




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




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",
                  
            }
        ];
    }
}




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




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




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




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",
                  
            }
        ];
    }
}




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




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


Article Tags :