Angular2-FormGroup包括和排除RC6中的替换
Angular2-FormGroup包括和排除RC6中的替换,angular,angular2-forms,Angular,Angular2 Forms,FormGroup类中的include和exclude方法在RC5中被弃用,然后在RC6中被删除 那么,我们应该如何构建条件验证呢?我们过去常常使用表单控件名调用include/exclude。addControl和removeControl是一种替代方法吗?在rc6(和未来版本)中,我使用AbstractControl启用和禁用方法解决了这个问题 例如: // before (rc5): //this.formGroup.exclude('controlName'); // after (r
FormGroup
类中的include
和exclude
方法在RC5中被弃用,然后在RC6中被删除
那么,我们应该如何构建条件验证呢?我们过去常常使用表单控件名调用include/exclude。addControl
和removeControl
是一种替代方法吗?在rc6(和未来版本)中,我使用AbstractControl启用和禁用方法解决了这个问题
例如:
// 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();
希望它能对您有所帮助。这不完全一样:现在调用disable()实际上会禁用(也称为灰显)控件,而exclude()没有这种副作用