Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable FormGroup controls in Reactives FormModule in Angular2

I am using Reactive FormsModule in Angular2. Now, I want to disable all controls of FormGroup. I can use readOnly property in all controls but it is not better solution as we might add new fields in near future.

So, Is there anyway to disable FormGroup controls in short ?

like image 537
Jeeten Parmar Avatar asked Feb 22 '17 15:02

Jeeten Parmar


2 Answers

Warning: if anyone is calling disable() inside of a an observable which is watching for changes on the form, you will want to pass in the argument {emitEvent: false}

like

control.disable({emitEvent: false});

This helped me avoid a Maximum call stack size exceeded Error.

like image 156
MShubat Avatar answered Oct 23 '22 16:10

MShubat


Now, I want to disable all controls of FormGroup

Use disable():

YOUR_FORM_GROUP.disable();

DEMO

like image 34
developer033 Avatar answered Oct 23 '22 15:10

developer033