Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed dropdown directive from dropdown treeview component #10

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {TreeviewConfig} from '../../models/treeview-config';
import {TreeviewComponent} from '../treeview/treeview.component';
import {TreeviewHeaderTemplateContext} from '../../models/treeview-header-template-context';
import {TreeviewItemTemplateContext} from '../../models/treeview-item-template-context';
import {DropdownDirective} from '../../directives/dropdown.directive';

@Component({
selector: 'ngx-dropdown-treeview',
Expand All @@ -20,6 +21,7 @@ export class DropdownTreeviewComponent {
@Output() selectedChange = new EventEmitter<any[]>(true);
@Output() filterChange = new EventEmitter<string>();
@ViewChild(TreeviewComponent, { static: false }) treeviewComponent: TreeviewComponent;
@ViewChild(DropdownDirective, { static: false }) dropdownDirective: DropdownDirective;
buttonLabel: string;

constructor(
Expand Down
9 changes: 7 additions & 2 deletions src/app/book/book.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,19 @@ <h3>Components (
<input class="form-check-input" type="checkbox" [(ngModel)]="dropdownEnabled"> Enable/disable
</label>
</div>
<div>
<label class="form-check-label">
<input class="form-check-input" type="checkbox" [(ngModel)]="closeOnSelection"> Close dropdown on selection
</label>
</div>
<div class="form-group form-inline">
<label>buttonClass</label>
<select class="form-control mx-sm-3" [(ngModel)]="buttonClass">
<option *ngFor="let c of buttonClasses" [value]="c">{{c}}</option>
</select>
</div>
<ngx-dropdown-treeview [config]="config" [items]="items" [buttonClass]="buttonClass"
(selectedChange)="values = $event" [disabled]="!dropdownEnabled"
<ngx-dropdown-treeview #dropdownTreeview [config]="config" [items]="items" [buttonClass]="buttonClass"
(selectedChange)="onSelectedChange($event)" [disabled]="!dropdownEnabled"
[ngxDisabledOnSelector]="'button.dropdown-toggle'" (filterChange)="onFilterChange($event)">
</ngx-dropdown-treeview>
</div>
Expand Down
14 changes: 12 additions & 2 deletions src/app/book/book.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, OnInit} from '@angular/core';
import {TreeviewConfig, TreeviewItem} from 'ngx-treeview2';
import {Component, OnInit, ViewChild} from '@angular/core';
import {DropdownTreeviewComponent, TreeviewConfig, TreeviewItem} from 'ngx-treeview2';
import {BookService} from './book.service';

@Component({
Expand Down Expand Up @@ -33,6 +33,9 @@ export class BookComponent implements OnInit {
];
buttonClass = this.buttonClasses[0];

@ViewChild('dropdownTreeview') dropdownTreeview: DropdownTreeviewComponent;
closeOnSelection = false;

constructor(
private service: BookService
) { }
Expand All @@ -44,4 +47,11 @@ export class BookComponent implements OnInit {
onFilterChange(value: string): void {
console.log('filter:', value);
}

onSelectedChange(event: any[]) {
this.values = event;
if (this.closeOnSelection) {
this.dropdownTreeview.dropdownDirective.close();
}
}
}
Loading