'Disable the entire form at once (Angular reactive form)
Is there any way to disable the entire form in angular when using Reactive forms. I know it is possible to make them disable one by one.
this.tempForm = this.fb.group({
m26_type: '',
m26_name: ''
})
this.tempForm.get('m26_type').disable();
Is it possible to disable the whole form rather than make every controller disable separately?
Solution 1:[1]
this.tempForm.disable();
Disables the control. This means the control will be exempt from validation checks and excluded from the aggregate value of any parent. Its status is DISABLED.
If the control has children, all children will be disabled to maintain the model.
UPDATE
Plunker link - https://plnkr.co/edit/CFC4uKpvfE4otJ2PWdkc?p=preview
Solution 2:[2]
If you use the template driven (with ngModel) you can add to your code also
<form #myForm="ngForm">
//at ts
//create view child
@viewChild('myForm')form:any;
//and in your function of reset
this.form.disable()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | rbr94 |