leovo2708 / ngx-treeview

An Angular treeview component with checkbox
MIT License
362 stars 337 forks source link

How to get checked text in onSelctionChange? #263

Open bharath3719 opened 4 years ago

bharath3719 commented 4 years ago

Hi i have this code for component

<ngx-dropdown-treeview [config]="config" [items]="items" (filterChange)="onFilterChange($event)" (selectedChange)="onSelectionChange($event)" [buttonClass]="buttonClass"

and in ts .

onSelectionChange(selectedValues: string[]) {
    console.log('selected values:', selectedValues);
    this.SelectedNodes = selectedValues;

}

I am getting only the selected value , how can i get the selected text ?

Rebel028 commented 4 years ago

You can do that if you get your dropdown-treeview as ViewChild. Like this: @ViewChild(DropdownTreeviewComponent , {static: false}) treeView: DropdownTreeviewComponent ;

Then you can access selected items as this.treeView.selection.checkedItems

danorr commented 3 years ago

Can confirm this also works for TreeviewComponent:

@ViewChild(TreeviewComponent) treeView: TreeviewComponent

Then you can access the treeview object by adding a (selectedChange)="nodeSelected($event)"

const selectedIds = this.treeView.selection.checkedItems.map(s => s.value); // mapping to a single value is optional