I am using Angular 7. And when I try to bind the value of a select
to a variable, the value is always parsed into something like "0: 25", "1: 50", "2: 75".
Example code below is for selecting a page size for a paginator. Where pageSizeOptions = [25, 50, 75, 100]
. Expected behavior is that pageSize
, bound to [(ngModel)]
, should contain a number
type and not a string. Using [value]
will return a stringified version of the value nd ngValue
returns the "[index]: [value]"
format.
<select
class="form-control"
(change)="onSelectPageSize($event.target.value)"
[ngModel]="pageSize"
>
<option *ngFor="let size of pageSizeOptions; let i = index" [ngValue]="size">
{{ size }}
</option>
</select>