I am facing an issue with a dropdown that I can't seem to reset. Despite clicking on "clear", the dropdown retains the last selection instead of resetting.
Although I have successfully reset another dropdown using the same method, I'm struggling to reset this particular dropdown. As a newcomer to angular, any assistance would be greatly appreciated.
<div class="db-dropdown">
<label for="dbdropdown">Site selection:</label>
<select required class="dbdropdown" name="dbdropdown" id="dbdropdown" [(ngModel)]="selectedLabel" (change)="onSelect(selectedLabel)" [disabled]="isRunning">
<option value='Please select DB'>Please select DB</option>
<option *ngFor="let option of options" [ngValue]="option.label">{{option.label}}</option>
</select>
<div *ngIf="selectedValues && selectedValues.length">
<app-connectionCode-dropdown></app-connectionCode-dropdown>
</div>
</div>
This is how I've set up ngOnInit in dropdown.ts:
ngOnInit() {
this.selectedLabel = this.dataService.selectedLabelDBSelection;
this.DBDropdownService.getOptions().subscribe(options => {
this.options = options;
});
this.dataService.isRunning$.subscribe(isRunning => this.isRunning = isRunning)
}
Here's the method I'm using to reset the selections in buttons.ts:
resetSelects() {
console.log('resetting selects');
this.dataService.setRunClick(false);
this.dataService.setSelectedValueDb('Please select DB');
this.dataService.setSelectedLabelDBSelection('Please select DB');
console.log('selectedLabelDBSelection:', this.dataService.selectedLabelDBSelection);
this.dataService.setSelectedValue('');
this.dataService.setSelectedProcedure('');
this.dataService.clearContents.next(true);
this.dataService.setIsRunning(false);
}
And here's the relevant method in the service:
setSelectedLabelDBSelection(value: string){
this.selectedLabelDBSelection = value;
}
selectedLabelDBSelection: string;