首页 > 解决方案 > 如何以正式的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",
}
]

标签: checkboxangular7angular-formly

解决方案


您需要在输入上有(更改)事件以查看复选框是否被选中

 <input type="checkbox" (change)="checkMethod($event)">

在你的 ts 文件中

  checkMethod(event)
{
if(event.target && event.target.checked)
{
//this means input is checked
}
}

推荐阅读