Reputation: 2923
I have the following code
<input [type]="'checkbox'" [(ngModel)]="inputValue">
<p>Value: {{ inputValue }}</p>
Can somebody explain why the value in inputValue
does not change?
I can't set just type="checkbox"
because I have dynamic type of input.
It works fine when type is text
or number
. It also works when the type of input is static (type="checkbox"
)
Upvotes: 2
Views: 651
Reputation: 60357
If dynamically setting the input type does not work why don't you try an ngSwitch
with a static input type for checkbox?
<ng-container [ngSwitch]="inputType">
<input *ngSwitchCase="'checkbox'" type="checkbox" [(ngModel)]="inputValue">
<input *ngSwitchDefault [type]="inputType" [(ngModel)]="inputValue">
</ng-container>
Check out this stackblitz.
Upvotes: 1