I have a dropdown box with a select event (selectionChange) implemented as shown below:
<mat-select #segmentSelector [formControlName]="filter.VAL" multiple placeholder="Select" (selectionChange)="someMethod($event.value, filter.VAL)">
<div class="custom-panel">
<ng-container *ngFor="let option of getFilterDropdownOptions(filter.VAL)">
<mat-option *ngIf="!!option" [value]="option" [value]="option">
{{ option }}
</mat-option>
</ng-container>
</div>
<footer class="select-box-footer">
<a class="select-box-footer-btn" (click)="$event.preventDefault();segmentSelector.close();">Done</a>
</footer>
</mat-select>
The selectionChange event works correctly when the value in the dropdown is changed:
someMethod(val: any, columnName: any) {
console.log(val);
var obj = val as [];
if (columnName === "CUST_ID") {
this.aLogData.customerId = [];
for (var i = 0; i < obj.length; i++) {
console.log(obj[i]);
this.aLogData.customerId.push(obj[i]);
}
}
if (columnName === "CUST_NAME") {
this.aLogData.customerName = [];
for (var i = 0; i < obj.length; i++) {
console.log(obj[i]);
this.aLogData.customerName.push(obj[i]);
}
}
var searchLocationInput = ((document.getElementById("searchLocationInput") as HTMLInputElement).value);
console.log(this.aLogData);
console.log(searchLocationInput);
this.aLogData.searchItem = searchLocationInput;
this.statusTwo = true;
setTimeout(() => this.delaySomeMthod(this.aLogData), 10000); //Attempting to delay sending data once
}
delaySomeMthod(aLogData: LogData) {
console.log("Called after 10 secs.");
this.locationService.setLogData(aLogData).subscribe();
}
However, I am facing an issue where the controller is called every time the dropdown data changes. I tried adding a timer but it seems like I need to control sending requests to the controller at specific intervals.
My requirement is to allow selecting and changing values in the dropdown multiple times, but only calling the service or controller once after a certain period, for example, 10 seconds, as I am updating an array. Is this achievable?