This module derivates from angular-tree-component. We remove the mobx dependency and do some performance improvements, whilst keep a similar component interface.
To install this library, run:
$ npm install @e-cloud/ngx-tree --save
NOTE: we use Element.closest, If you want to compromise with IE 11, please apply the polyfill https://github.com/jonathantneal/closest to your probject.
For details, please take a look at document site
Once you have installed the library, you can import it in your Angular AppModule
:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
// Import your library
import { NgxTreeModule } from '@e-cloud/ngx-tree';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
// Specify your library as an import
NgxTreeModule.forRoot()
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
<!-- You can now use your library component in app.component.html -->
<h1>
{{title}}
</h1>
<ngx-tree
[nodes]="nodes"
[dataOptions]="customOptions">
<ng-template #treeNodeTemplate let-node="node">
<span title="{{node.data.subTitle}}">{{ node.data.name }}</span>
</ng-template>
</ngx-tree>
NOTE: the minimum input for
ngx-tree
component isnodes
.
There is a forRoot()
method on NgxTreeModule
, which should be used only on root module of apps.
forRoot
injects two providers, TreeDraggingTargetService
and VIRTUAL_SCROLL_NODE_HEIGHT_QUOTA
. The first holds the dragging element. The other specify the round size to calculate the average tree item height.
We split the tree options into two category, TreeDataOptions
and TreeUIOptions
. dataOptions
inputted by user will be passed into TreeModel
which handle the tree data operations. uiOption
will be passed into every child components required and declared tree templates(will introduce late).
We predefine five tree templates for flexible customization.
loadingTemplate
- loading indicator for async nodesexpanderTemplate
- for tree expander customization,treeNodeTemplate
- for customization of tree node contents(not including node children components and node expander, only for every single node's content)treeNodeWrapperTemplate
- treeNodeTemplate
+ full customization over expandertreeNodeFullTemplate
- treeNodeWrapperTemplate
+ full customization over how the node children display.To generate all *.js
, *.d.ts
and *.metadata.json
files:
$ npm run build
To lint all *.ts
files:
$ npm run lint
MIT © e-cloud