angular - 以角度输入为条件,从其他输入中获取计算值
问题描述
好的,所以我有一个只读的输入,它从其他输入中获取它的值,然后我试图运行一个条件来根据正在填充的输入值显示或隐藏。
<input id="incomeOutput" readonly="readonly "name="incomeOutput"
[(ngModel)]="incomeOutput" [value]="[monthly_pension.value*12 +
monthly_investments.value*12 + monthly_annuities.value*12 +
monthly_SSI.value*12]" >
然后我有条件地检查像这样
[hidden]="(this.stepTwo.classList.value === 'step active' && (this.incomeOutput === 0))"
我已经incomeOuput
设置了一个数字。
但是当我控制台incomeOutput
它出现未定义时,我从来没有看到在条件期间所做的更改。除此以外,条件在所有情况下都可以正常工作。
解决方案
您不能使用 [(ngModel)] - 两种绑定方式 - 与 [value] 一起为一个变量赋值。
您可以使用模板引用变量(但模板引用变量,在 .html 中允许您访问 htmlInput,因此您可以使用incomeOutput.value - 在这种情况下,“值”是一个字符串 -)。
<!--the #incomeOutput, indicate that is a template reference variable-->
<!--see also that not use [ ]-->
<!--and you need use a "+" to convert to "number",
in general the [(ngModel)] give us a "string"
-->
<input #incomeOutput" readonly="readonly "name="incomeOutput"
[ngModel]="+monthly_pension.value12 + (+monthly_investments.value12)
+ (+monthly_annuities.value12) + (+monthly_SSI.value12)" >
<!--see how access to "value" of the htmlElement and the "+" before
to convert To Number-->
<div [hidden]="(this.stepTwo.classList.value === 'step active' &&
+incomeOutput.value==0>
愚蠢的堆栈闪电战
推荐阅读
- django - 如何在 django 中为管理员编写自定义视图?
- vue.js - 如何构建/编译要在运行时与 vue 一起使用的 vue 组件?
- c# - 从 DateTime 中删除时间部分
- asp.net-core - 使用 MassTransit 订阅 ActiveMQ 主题
- c++ - 两个“稀有”矩阵的总和,读作坐标 X、坐标 Y 和一个值
- javascript - 使用 javascript/jquery 在 Internet Explorer 中使用 POST 数据打开链接
- python - 如何在编辑期间启用日期格式,同时仍应用清晰的表单
- android - Android - 日期与给定格式不对应
- 3d - 如果添加了平移,如何正确计算 3D Procrustes 问题中的旋转?
- java - 如何确定 Wildfly 10 支持的密码套件