我有一个角度4.10的应用程序,使用剑道角度网格控制。我正在使用外部编辑。我已经创建了如下表单组:
this.editForm = new FormGroup({
'Id': new FormControl({ value: 0, disabled: true }),
'Name': new FormControl("", Validators.compose([Validators.required, Validators.maxLength(30)])),
'BlindName': new FormControl({ value: "" }, Validators.compose([Validators.required, Validators.maxLength(30)])),
'UnitText': new FormControl(0),
'IsFromBsp': new FormControl(true),
'Disabled': new FormControl(false),
'SortOrder': new FormControl(0, Validators.compose([Validators.required, Validators.pattern('\\d')]))
});
我想做的是根据值isfromsp设置字段blindname的禁用状态。类似于:
'BlindName': new FormControl({ value: "", disabled: this.IsFromBsp }, Validators.compose([Validators.required, Validators.maxLength(30)])),
有办法做到这一点吗?请告诉我。
谢谢
最佳答案
如果IsFromBsp
是true
的话,我假设您要禁用输入字段。如果这只是最初需要的,则可以在生成窗体后运行函数:
check() {
if(this.editForm.get('IsFromBsp').value == true) {
this.editForm.get('BlindName').disable()
}
}
如果此值更改,则必须在某个更改事件上再次调用此函数,或者使用
(change)
或使用valueChanges
监视窗体值的更改,如果该值不是true
值,则可以执行this.editForm.get('BlindName').enable()
再次启用它。这适用于“常规”反应形式,希望也与剑道。关于angular - 如何动态设置Angular react 形式的禁用状态?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44289740/