Generic Dropdown
The GenericDropdownComponent is a dynamic Angular component for creating customizable dropdown menus. It supports both static and remote data sources, lazy loading for performance optimization, and translation for option labels. Designed to integrate seamlessly with Angular applications, it enables real-time data updates, event-driven interactions, and flexible configurations for various use cases.
How to use the component in your app :
import the component :
import {GenericDropdownComponent} from '@tradinos/cms-frontend-form';The selector for component , like it :
<lib-cms-generic-dropdown></lib-cms-generic-dropdown>Features
Dynamic and Static Data Support:
Fetches dropdown options from static lists or remote data sources via API endpoints.
Lazy Loading:
Optimized for large datasets with lazy loading support through
ScrollerOptions.
Translation Support:
Translates dropdown option labels using the PrimeNG translation service.
Customizable Behavior:
Fully configurable via the
DropdownConfigurationobject, allowing customization of labels, value mapping, and more.
Pre-Selection:
Automatically selects options based on predefined indices or custom logic (
indexFn).
Event-Driven:
Emits
optionChangeandvalueChangeevents for real-time integration with parent components.
Caching:
Uses
HttpCacheManagerto cache API responses, optimizing repeated requests for the same data.
Validation States:
Handles
disabledandinvalidstates for enhanced form integration.
Loading State:
Displays a loading indicator while fetching data from remote sources.
Inputs
Input
Type
Description
Default value
configuration
DropDownConfiguration
The key used to uniquely identify the data being updated.
-
disabled
boolean | null
A dictionary of custom templates to customize specific parts of the form.
null
option
any
The initial data to pre-fill the form fields.
-
loading
boolean
Controls whether the submit button is displayed.
false
invalid
boolean
Marks the component as invalid when set to true.
false
placeHolder
string
Placeholder text for the dropdown.
-
This is the options in DropDownConfiguration type:
For example:
Outputs
Output
Type
Description
optionChange
EventEmitter<any>
Emits the selected option whenever the user makes a selection.
valueChange
EventEmitter<any>
Emits the value of the selected option.
Methods
1. ngOnInit()
Description:
Initializes the dropdown by setting up options, applying translations, and handling reactive streams for dynamic updates.
Parameters: None.
2. fetchOptions(endPoint: string, queryParams?: any): void
Description:
Fetches options from a remote data source and updates the dropdown list.
Uses caching for optimization and applies a response mapping function (
mapHttpResponse).
Parameters:
endPoint: The API endpoint URL.queryParams(optional): Additional query parameters for the API request.
3. selectIndex(value?: number): void
Description:
Selects an option based on a predefined index or custom logic (
indexFn).
Parameters:
value(optional): Index of the option to select.
4. onChange(event: Partial<DropdownChangeEvent>): void
Description:
Handles option selection changes and emits the
optionChangeandvalueChangeevents.
Parameters:
event: The change event containing the selected option.
Last updated