简体   繁体   English

如何在反应形式的角度禁用FormControl?

[英]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.

相关问题 如何在 Angular 15 的条件下禁用反应式表单中的输入 FormControl? - How to disable an input FormControl in a Reactive Form with a condition in Angular 15? 如何在 angular 中禁用表单控件 select 和表单控件 - how to disable formcontrol select and form control in angular Angular Reactive Form 在其他表单中使用 formControl - Angular Reactive Form Use a formControl in an other form 将角形反应形式FormControl绑定到动态值 - binding a angular reactive form FormControl to a dynamic value 在Angular反应形式中读取复选框FormControl值 - Reading Checkbox FormControl value in Angular Reactive Form Angular Reactive Form检查Test中是否存在FormControl - Angular Reactive Form check if FormControl is existing in Test 如何在 Angular 4 的 FormArray 中禁用 FormControl - How to disable FormControl in FormArray in Angular 4 Angular 5 Reactive表单:如何在表单控件上动态添加验证器,以及在用户提交表单时显示错误 - Angular 5 Reactive form : how to dynamically add validators on a formcontrol, and show errors when a user submits the form Angular 反应式 forms,基于另一个表单上的 FormControl 验证一个表单 - Angular reactive forms, validating one form based on a FormControl on another form 反应式表单:如何使用 Angular 上的 FormControl 将输入值捕获到组件内的变量中,而不使用 [(ngModel)]? - Reactive form: How to capture the input value into a variable within component using FormControl on Angular WITHOUT [(ngModel)]?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM