<select [(ngModel)]="detail.State" (ngModelChange) ="onStateChange()" class="form-control">
<option [ngValue]="null" disabled selected>Select State</option>
<option *ngFor="let option of stateData" [ngValue]="option.KeywordValueText">{{option.KeywordValueText}}</option>
</select>
<select [(ngModel)]="detail.City" class="form-control">
<option [ngValue]="null" disabled selected>Select City</option>
<option *ngFor="let option of cityData" [ngValue]="option.KeywordValueText">{{option.KeywordValueText}}</option>
</select>
In the .ts file, a function is defined as:
onStateChange() {
this.detail.City = 'null';
let selectedState = this.keywords.State.filter((val: { KeywordValueText: string | undefined; }) => val.KeywordValueText === this.detail.State);
this.cityData = this.keywords.City.filter((val: { ParentID: any; }) => val.ParentID == selectedState[0].KeywordValueID);
}
The requirement is to have default selections for both Choose State and Choose City. When the state is changed, the city should revert back to Choose City. Assistance in achieving this functionality is appreciated.