Angular UI Components Documentation
The Angular DropDownButton shows any content in a drop-down that opens from a button. This guide adds the Angular DropDownButton (jqxDropDownButton) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-ngjqwidgets-ng/jqxdropdownbutton In an Angular project (to start one, see Getting started with Angular), add the package with the Angular CLI. It asks for a theme and adds the styles to angular.json:
ng add jqwidgets-ng
Components are standalone: add jqxDropDownButtonModule to the imports of the component that uses it.
import { Component } from '@angular/core';
import { jqxDropDownButtonModule } from 'jqwidgets-ng/jqxdropdownbutton';
@Component({
selector: 'app-root',
imports: [jqxDropDownButtonModule],
templateUrl: './app.html'
})
export class App {}
The source of the live DropDown Button demo.
<jqxDropDownButton #myDropDownButton style="float: left"
[width]="150" [height]="25">
<jqxTree #myTree
(onSelect)="treeOnSelect($event)" [width]="200">
<ul>
<li item-selected='true'>Home</li>
<li item-expanded='true'>
Solutions
<ul>
<li>Education</li>
<li>Financial services</li>
<li>Government</li>
<li>Manufacturing</li>
<li>
Solutions
<ul>
<li>eLearning</li>
<li>Mobile</li>
<li>RIA</li>
<li>Training</li>
</ul>
</li>
</ul>
</li>
<li>
Products
<ul>
<li>PC products</li>
<li>Mobile products</li>
<li>All products</li>
</ul>
</li>
</ul>
</jqxTree>
</jqxDropDownButton>
<div style="float: left; margin-top: 5px; margin-left: 30px">
<jqxCheckBox (onChange)="checkBoxOnChange($event)">
Open On Mouse Over
</jqxCheckBox>
</div>
import { Component, AfterViewInit, ViewEncapsulation, viewChild } from '@angular/core';
import { jqxDropDownButtonComponent } from 'jqwidgets-ng/jqxdropdownbutton';
import { jqxTreeComponent } from 'jqwidgets-ng/jqxtree';
import { CommonModule } from '@angular/common';
import { jqxDropDownButtonModule } from 'jqwidgets-ng/jqxdropdownbutton';
import { jqxCheckBoxModule } from 'jqwidgets-ng/jqxcheckbox';
import { jqxTreeModule } from 'jqwidgets-ng/jqxtree';
@Component({
imports: [CommonModule, jqxDropDownButtonModule, jqxCheckBoxModule, jqxTreeModule],
selector: 'app-root',
templateUrl: './app.html',
styleUrl: './app.css',
encapsulation: ViewEncapsulation.None
})
export class App implements AfterViewInit {
readonly myDropDownButton = viewChild.required<jqxDropDownButtonComponent>('myDropDownButton');
readonly myTree = viewChild.required<jqxTreeComponent>('myTree');
ngAfterViewInit(): void {
this.myDropDownButton().setContent(
'<div style="position: relative; margin-left: 3px; margin-top: 4px;">Home</div>'
);
}
treeOnSelect(event: any): void {
if (this.myTree()) {
let item = this.myTree().getItem(event.args.element);
let dropDownContent = `<div style="position: relative; margin-left: 3px; margin-top: 4px;">${item.label}</div>`;
this.myDropDownButton().setContent(dropDownContent);
}
}
checkBoxOnChange(event: any): void {
this.myDropDownButton().autoOpen(event.args.checked);
}
}
jqxTree div {
border: none !important;
}
Options are inputs, bound with [name]="value".
Events are outputs named on plus the event name with a capital first letter. For example, open: This event is triggered when the button's popup is opened.
<jqxDropDownButton (onOpen)="onOpen($event)"></jqxDropDownButton>
onOpen(event: any): void {
console.log(event.args);
}
Get the component with a signal query and call its methods. For example, open: Shows the button's content.
<jqxDropDownButton #myDropDownButton></jqxDropDownButton>
import { Component, viewChild } from '@angular/core';
import { jqxDropDownButtonModule, jqxDropDownButtonComponent } from 'jqwidgets-ng/jqxdropdownbutton';
@Component({
selector: 'app-root',
imports: [jqxDropDownButtonModule],
templateUrl: './app.html'
})
export class App {
readonly myDropDownButton = viewChild.required<jqxDropDownButtonComponent>('myDropDownButton');
run(): void {
this.myDropDownButton().open();
}
}