checkbox - 如何以正式的angular7检测复选框选中事件?
问题描述
使用 formly 和 Json 我创建了一个表单。现在我想在选中复选框时显示一个文本框。
我尝试了ngDoCheck()
方法,但无法显示文本。该box.this
方法会触发每个字段单击事件,尽管我只需要检查事件。任何人都可以帮我解决这个问题。
"createConfig": [
{
"columnName": "chkid",
"columnSize": 50,
"columnType": 5,
"discreteValues": null,
"displayName": "",
"filterType": "e",
"isEnabled": 1,
"isMultiSelect": 0,
"isRequired": 0,
"isVisible": 1,
"listDataProvider": null,
"position": 2,
"showSuggestion": 1,
"sizeUnit": "px",
"useDisplayValueOnly": 1
},
{
"columnName":"nonusaddresa",
"displayName": "Address1/Address2/City/State/Zip/PostalCode/Country",
"position": 2,
"columnType": 1,
"isSortable": 0,
"defaultSortOrder": null,
"columnSize": 800,
"sizeUnit": "px",
"isVisible": 0,
"isEnabled": 1,
"isRequired": 0,
"isMultiSelect": 0,
"showSuggestion": 1,
"useDisplayValueOnly": 1,
"filterType": "e",
}
]
解决方案
您需要在输入上有(更改)事件以查看复选框是否被选中
<input type="checkbox" (change)="checkMethod($event)">
在你的 ts 文件中
checkMethod(event)
{
if(event.target && event.target.checked)
{
//this means input is checked
}
}
推荐阅读
- python-3.x - Pandas:导入多个 CSV 文件并追加在一起,使元素按照时间索引排列
- sql - 可以从 PL/SQL Oracle 中的正在进行的游标中删除字段吗?
- constructor - 在 F# 类中,如何在初始化时使用另一个值中的值?
- algorithm - 哪种排序方法最适合对大小为 0 到 2^40 的 100 万个整数进行排序,以便获得最小的波浪号时间复杂度?
- c# - 如何在 c# 中禁用 HeaderText Click?
- r - 假设我不知道数据框中的列名,如何根据该列中的值对 df 进行排序?
- python - PyTorch,按元素应用不同的功能
- python - 如何为文件中的每个单词添加数字组合?
- java - 如何搜索该列表
包含使用流的字符串的给定数组 [] 的所有值? - c++ - 从 boost fusion 适应结构中获取成员类型列表