[英]How to conditionally set input tag's max value base on a value of a Angular component's variable
I have 3-way input control is defined as following我有3路输入控制定义如下
<input type="range" min="0" max="2" formControlName="dhwOption" class="form-control-range" style="width:180px" id="myonoffswitch2">
I would like to dynamically set the range from 2 to 1 using a component class variable's value, it does not work我想使用组件 class 变量的值动态设置从 2 到 1 的范围,它不起作用
<input type="range" min="0" max= {*ngIf="appEngineMsg && appEngineMsg.Type === 0"}?"1" :"2" formControlName="dhwOption" class="form-control-range"
Remove the braces and quotes and try the following code, assuming appEngineMsg is a variable in the .ts
删除大括号和引号并尝试以下代码,假设 appEngineMsg 是
.ts
中的变量
<input type="range" min="0" max="appEngineMsg && appEngineMsg.Type === 0 ? 1 : 2" formControlName="dhwOption" class="form-control-range"
You should use property binding syntax and take advantage of the safe navigation operator :您应该使用属性绑定语法并利用安全导航运算符:
[max]="appEngineMsg?.Type === 0 ? 1 : 2"
This is a working solution for my own project这是我自己的项目的有效解决方案
<input type="range" min="0" max='{{appEngineMsg && appEngineMsg.Type === 0 ? 1 : 2}}'>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.