I am using PrimeNG controls. I am setting the disabled attribute on various input controls via a directive and some of the controls are p-dropdown, p-listbox and p-calendar PrimeNG controls. The basic input, textarea and select controls work just find, but the PrimeNG controls have disable defined as @Input as follows:
private _disabled: boolean;
@Input() get disabled(): boolean {
return this._disabled;
};
and a code snippet of the directive is as follows:
/*
** 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');
}
}
}
So, how to disable the PrimeNG 3rd party controls given a ElementRef.nativeElement? I am thinking, I need a way to fulfill the disabled @Input property given an element reference.