I am working on a dropdown component that utilizes the @Input
decorator to define a function with arguments, returning a boolean value.
dropdown-abstract.component.ts
@Input() public itemDisabled: (itemArgs: { dataItem: any; index: number }) => boolean = () => false;
license-add.component.html
<hf-shared-dropdown-small class="license-card__row-input"
[id]="'expiryDate'"
[required]="false"
[itemDisabled]="itemDisabled"
[isConfirmable]="false"
[data]="expiryDates"
[value]="selectedExpiryDate"
(valueChange)="dateSelect($event)">
</hf-shared-dropdown-small>
license-add.component.ts
public getCustomer(): void {
this.loading = true;
this.customerService.getCustomer(this.customerId)
.pipe(first(), finalize(() => this.loading = false))
.subscribe((response: CustomerResponse) => {
if (response && response.success) {
this.customerName = response.name;
this.registeredTo = response.tradingName ?? response.name;
this.locationCount = response.licensedLocCount;
this.employeeCount = response.licensedEmpCount;
//here we set the contract end date to use
this.contractEndDate = response.contractEndDate;
sessionStorage.setItem("contractEndDate",this.contractEndDate.toString());
if (response.contractEndDate && response.contractEndDate > 0) {
this.selectedExpiryDate = this.expiryDates[3];
this.dateSelect(this.selectedExpiryDate);
}
} else {
this.modalService.showInfoPopup({ title: 'Ooops!', text: 'Customer missing.', showIcon: true, popupType: PopupTypes.Error });
}
},
(error: any) => {
this.modalService.showInfoPopup({ title: 'Ooops!', text: error, showIcon: true, popupType: PopupTypes.Error });
});
}
An additional @Input
function is defined in this component:
public itemDisabled(itemArgs: { dataItem: IdNameValue; index: number; date: number}) {
console.log(this.contractEndDate)
if ((this.contractEndDate)) {
if (itemArgs.dataItem.id === LicensePeriod.ContractEndDate) {
return true;
}
}
return false;
}
However, when trying to access the itemDisabled
function, this.contractEndDate
appears as undefined
, even though its value had been previously set.