Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 - FormGroup include and exclude replacements in RC6

include and exclude methods in FormGroup class were deprecated in RC5 and then removed in RC6.

So, how are we supposed to build conditional validation? We used to call include/exclude with form control name. Are addControl and removeControl an alternative?

like image 322
user2363245 Avatar asked Aug 15 '26 02:08

user2363245


1 Answers

In rc6 (and future versions) I've solved this issue by using AbstractControl enable and disable methods.

Example:

// before (rc5):
//this.formGroup.exclude('controlName');

// after (rc6):
this.formGroup.get('controlName').disable();

// before (rc5):
this.formGroup.include('controlName');

// after (rc6):
this.formGroup.get('controlName').enable();

Hope it helps you.

like image 80
pauplanas Avatar answered Aug 17 '26 17:08

pauplanas