4
To use NGX Treeview with Bootstrap5 and Angular 16, you can follow these steps:
- Setting up Angular Project: Create a new Angular project using the Angular CLI:
ng new angular-ngx-treeview-example
cd angular-ngx-treeview-example
- Installing ngx-treeview: Install the ngx-treeview library:
npm install ngx-treeview
Then, import the TreeviewModule
in your app.module.ts
file:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { TreeviewModule } from 'ngx-treeview';
@NgModule({
declarations: [ AppComponent ],
imports: [ BrowserModule, TreeviewModule.forRoot() ],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
- Adding Hierarchical Tree Structure: Define the data in the
app.component.ts
file and add the following code to your app.component.html
file:
<ngx-treeview [items]="treeItems"></ngx-treeview>
- Adding Checkboxes: To add checkboxes to tree nodes, modify the
app.component.html
file with the hasAllCheckBox
and hasFilter
attributes:
<ngx-treeview [items]="treeItems" [config]="config"></ngx-treeview>
Update the class file as shown below with changes in the config object:
import { Component } from '@angular/core';
import { TreeviewConfig, TreeviewItem } from 'ngx-treeview';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
public treeItems: TreeviewItem[];
public config: TreeviewConfig;
constructor() {
// ...
this.config = {
hasAllCheckBox: true,
hasFilter: false,
hasCollapseExpand: true,
decoupleChildFromParent: false,
maxHeight: 500,
hasDivider: true,
};
}
}
Please note that the ngx-treeview library may not be fully compatible with Angular 161. If you encounter compatibility issues, you might need to consider using another library1. You can also check out different implementations of ngx-treeview on npm1.
Thanks

3
Considering an open issue with the current library, you might have to explore some alternative options.
https://github.com/leovo2708/ngx-treeview/issues/345
Exploring other libraries could be a prudent approach for your specific use case.
3
While NGX Treeview is a popular option for treeview components in Angular, it currently has limited compatibility with Angular 16 due to its dependency on Bootstrap 4. There are two main approaches for using a treeview component with Bootstrap 5 and Angular 16:
1. Alternative libraries:
Several libraries offer treeview components compatible with Bootstrap 5 and Angular 16. Here are two popular options:
-
@angular/material
: Angular Material provides a well-maintained and feature-rich treeview component. It seamlessly integrates with the Material Design system and offers features like multi-selection, filtering, and custom rendering.
-
ngx-bootstrap-treeview
: This library offers a treeview component based on Bootstrap 5. It provides basic features like collapsing/expanding nodes, checkboxes, and custom templates.
2. Custom solution:
If you need more control over the look and feel or have specific requirements, you can build your own treeview component using pure Angular and Bootstrap 5 classes. This approach requires more development effort but offers maximum flexibility.

3
To use NGX Treeview with Bootstrap 5 and Angular 12, you need to follow these steps:
-
Install the required dependencies:
-
npm install ngx-treeview bootstrap@5
- Import the necessary modules in your Angular module file (e.g.,
app.module.ts
):
-
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { TreeviewModule } from 'ngx-treeview';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, TreeviewModule.forRoot()],
bootstrap: [AppComponent]
})
export class AppModule { }
- Import the Bootstrap styles in your
styles.scss
file:
-
@import '~bootstrap/dist/css/bootstrap.css';
- Use the
ngx-treeview
component in your Angular component:
-
<ngx-treeview [items]="treeItems"></ngx-treeview>
-
import { Component } from '@angular/core';
import { TreeviewItem } from 'ngx-treeview';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
treeItems: TreeviewItem[] = [
new TreeviewItem({ text: 'Item 1', value: 1 }),
new TreeviewItem({ text: 'Item 2', value: 2 })
];
}
-
Customize the treeview component according to your requirements by referring to the NGX Treeview documentation.
