2

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")

Kim Kern
  • 54,283
  • 17
  • 197
  • 195
Valera
  • 2,665
  • 2
  • 16
  • 33

1 Answers1

1

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.

Kim Kern
  • 54,283
  • 17
  • 197
  • 195