Issue
I need to get the selected dropdown value when changed
But when I set the value with ngValue, it is prepending an index
(makes no sense why)
How can I get just the value?
Actual values in source
Index added to value!?
0: Campus A
1: Campus B
2: Campus C
<form [formGroup]="preferredCampus">
<select id="campus" formControlName="campus" #t (change)="campusChanged(t.value)">
<option *ngFor="let i of campusInfo.campuses" [ngValue]="i.Name">{{ i.Name }}</option>
</select>
</form>
Solution
Use [value]
rather than [ngValue]
in this situation.
Using [value]
works well with simple values, like strings.
[ngValue]
is best used when you want to use an object as a value.
More details: https://angular.io/api/forms/SelectControlValueAccessor#how-to-use
Answered By - R. Richards
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.