[英]How to disable FormControl in Reactive Form Angular?
How to disable this formControl: 如何禁用此formControl:
this.step1 = this.fb.group({
'name': ['', [Validators.required, Validators.minLength(1), Validators.maxLength(50)], disabled: true]...
I tried to add: 我尝试添加:
disabled: true
I'm not sure this works 我不确定这行得通
'name': [{
value: '',
disabled: true
}, [Validators.required, Validators.minLength(1), Validators.maxLength(50)], disabled: true]
But I am sure this does 但是我敢肯定
'name': new FormControl([{
value: '',
disabled: true,
validators: [Validators.required, Validators.minLength(1), Validators.maxLength(50)], disabled: true]
})
use disabled:true
for this. 为此使用disabled:true
。
this.step1 = this.fb.group({
name: [{value:'name',disabled:true}, [Validators.required, Validators.minLength(1), Validators.maxLength(50)]],
lastname: [{value:'last name',disabled:true}, [Validators.required, Validators.minLength(1), Validators.maxLength(50)]]
})
You must add that to formState
- 1st parameter of fb.control
: 您必须添加到formState
-的第一个参数fb.control
:
this.step1 = this.fb.group({
'name': this.fb.control({value: '', disabled: true}, [Validators.required, Validators.minLength(1), Validators.maxLength(50)])
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.