2
include
和exclude
FormGroup
中的方法在RC5中被棄用,然後在RC6中被刪除。Angular2 - FormGroup在RC6中包含和排除替換
那麼,我們應該如何構建條件驗證?我們通常使用表單控件名稱來調用include/exclude。是addControl
和removeControl
的替代?
include
和exclude
FormGroup
中的方法在RC5中被棄用,然後在RC6中被刪除。Angular2 - FormGroup在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()現在實際上禁用(aka灰色)控件,而exclude()沒有這個副作用 – user2363245