javascript - Angular 5中类型复选框的动态输入
问题描述
我有以下代码
<input [type]="'checkbox'" [(ngModel)]="inputValue">
<p>Value: {{ inputValue }}</p>
有人可以解释为什么 in 的值inputValue
不会改变吗?
我不能仅仅type="checkbox"
因为我有动态类型的输入而设置。
当 type 为text
or时它工作正常number
。它也适用于输入类型为静态 ( type="checkbox"
)
解决方案
如果动态设置输入类型不起作用,为什么不尝试ngSwitch
使用静态输入类型作为复选框?
<ng-container [ngSwitch]="inputType">
<input *ngSwitchCase="'checkbox'" type="checkbox" [(ngModel)]="inputValue">
<input *ngSwitchDefault [type]="inputType" [(ngModel)]="inputValue">
</ng-container>
看看这个stackblitz。
推荐阅读
- ios - Flutter 可以实现 iOS 原生 iOS11 拖放功能吗?
- spring-boot - Spring Boot 2.1 与嵌入式 Tomcat 与 http/2 和 ssl,gzip 不工作
- python - Adding a new level to a dataframe
- c++ - 简化存储在类的 std::vector 成员中的 std::function 的使用
- c# - 读取串行端口并将其存储在字符串变量 C#
- javascript - 防止将整个节点集中在孩子身上
- sorting - 排序后保留参考资料 - 是否有电子表格应用程序或执行此操作的选项?
- ios - 如何在 swift 中清除 AR 节点中的白层背景?
- ios - UItableViewCell 上的 CABasicAnimation
- python - 如何使用 python selenium 单击 youtube 评论中的链接