html:
通过ngModelChange 各自绑定一个方法 对文本框进行实时监控
<input type="text" pInputText id="createCoreDeviceNameId" (ngModelChange) = "checkSaveBtnByDeviceName($event)" [(ngModel)]="deviceName" />
<input type="text" pInputText id="createCoreThingGroupName" (ngModelChange) = "checkSaveBtnByThingName($event)" [(ngModel)]="thingGroupName" />
ts文件:
checkSaveBtnByDeviceName(deviceName) {
this.checkSaveBtn(deviceName, this.thingGroupName);
}
checkSaveBtnByThingName(thingGroupName) {
this.checkSaveBtn(this.deviceName, thingGroupName);
}
checkSaveBtn(deviceName: string, thingGroupName: string) {
if (!deviceName || (!thingGroupName &&this.radioButton ==="oneRadioButton")) {
this.saveBtnIfDisable = true;
} else {
this.saveBtnIfDisable = false;
}
}
效果如下:
当文本框全部不为空时 保存按钮可以使用