Utilizing PrimeNG components, I am implementing the disabled attribute on different input controls using a directive. Among them are the p-dropdown, p-listbox, and p-calendar PrimeNG controls. While the standard input, textarea, and select controls work smoothly, the PrimeNG controls have disable defined as @Input in the following manner:
private _disabled: boolean;
@Input() get disabled(): boolean {
return this._disabled;
};
Here is a snippet of the directive:
/*
** Find all inputs and disable them.
*/
disableElements(el: ElementRef): void {
const controls = el.nativeElement.querySelectorAll('input, select, textarea, p-dropdown, p-listbox, p-checkbox');
controls.forEach((elmt: any) => {
this.disableElement(elmt);
});
}
/*
** Disable an input element.
*/
disableElement(elmt: any): void {
if (elmt.localName.substr(0, 2) === 'p-') {
this._renderer.setProperty(elmt, 'disabled', 'true');
} else {
if (!elmt.hasAttribute('disabled')) {
this._renderer.setAttribute(elmt, 'disabled', 'true');
}
}
}
Hence, the question arises: how can I disable the PrimeNG third-party controls with an ElementRef.nativeElement? I am contemplating on a method to satisfy the disabled @Input property with respect to an element reference.