Jeeten Parmar
Jeeten Parmar

Reputation: 5757

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 ?

Upvotes: 17

Views: 42613

Answers (2)

MShubat
MShubat

Reputation: 661

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.

Upvotes: 11

developer033
developer033

Reputation: 24864

Now, I want to disable all controls of FormGroup

Use disable():

YOUR_FORM_GROUP.disable();

DEMO

Upvotes: 50

Related Questions