When a user loads a different selection (object) from the option drop-down list, I would like to get the NEW object returned in the (change) function. But, it is returning the default object every time, even though the select changes correctly. This type of binding was working in AngularJs when using $scope. Not sure if my Angular 11 ngModel, etc. is correct. (I have imported FormsModule)
component.ts...
public selectedQuery: any;
// default object...
public myQueries: [{
myQueryId: number,
myQueryCreatedDate: Date,
myQueryString: string
}] = [{
myQueryId: 0,
myQueryCreatedDate: new Date(),
myQueryString: "Please select a query"
}]
dropDownListBuild(); // function builds correctly, loads myQueries array with options
...
this.selectedQuery = this.myQueries[0]; // gets set as default
...
onQueryChange(query: any) {
console.log(this.selectedQuery + query); // not seeing any change happen
}
component.html...
<div class="selectClass">
<select [(ngModel)]="selectedQuery" (change)="onQueryChange(selectedQuery)">
<option *ngFor="let opt of myQueries" [ngValue]="selectedQuery"> {{opt.myQueryString}}</option>
</select>
</div>