如何基于Angular组件变量的值有条件地设置输入标签的最大值

时间:2019-10-11 18:23:48

标签: html angular

我有3路输入控制,定义如下

<input type="range" min="0" max="2" formControlName="dhwOption" class="form-control-range" style="width:180px" id="myonoffswitch2">

我想使用组件类变量的值动态设置2到1的范围,它不起作用

 <input type="range" min="0" max= {*ngIf="appEngineMsg && appEngineMsg.Type === 0"}?"1" :"2" formControlName="dhwOption" class="form-control-range"

2 个答案:

答案 0 :(得分:1)

假定.ts中的appEngineMsg是变量,请删除大括号和引号,然后尝试以下代码。

<input type="range" min="0" max="appEngineMsg && appEngineMsg.Type === 0 ? 1 : 2" formControlName="dhwOption" class="form-control-range"

答案 1 :(得分:1)

您应该使用property binding syntax并利用safe navigation operator

[max]="appEngineMsg?.Type === 0 ? 1 : 2"