Angular 5 中类型复选框的动态输入

Dynamic input of type checkbox in Angular 5

我有以下代码

<input [type]="'checkbox'" [(ngModel)]="inputValue">
<p>Value: {{ inputValue }}</p>

有人可以解释为什么 inputValue 中的值没有改变吗?

我不能只设置 type="checkbox" 因为我有动态输入类型。

类型为textnumber时工作正常。当输入类型为静态时它也有效 (type="checkbox")

如果动态设置输入类型不起作用,为什么不尝试 ngSwitch 复选框的静态输入类型?

<ng-container [ngSwitch]="inputType">
    <input *ngSwitchCase="'checkbox'" type="checkbox" [(ngModel)]="inputValue">
    <input *ngSwitchDefault [type]="inputType" [(ngModel)]="inputValue">
</ng-container>

看看这个 stackblitz