Providing disabled
property as true inside FormControl surely disables the input field.
this.form=this.fb.group({
FirstName:[{value:'first name', disabled:true}],
LastValue:['last name,[Validators.required]]
})
The above example will disable the FirstName
input field.
But real problem arises when you try to access disabled field value through form like this
console.log(this.form.value.FirstName);
and it shows as undefined
instead of printing field's actual value. So, to access disabled field's value, one must use getRawValue()
method provided by Reactive Forms
. i.e. console.log(this.form.getRawValue().FirstName);
would print the actual value of form field and not undefined.