我有一个带有一堆 ng-select 元素的 FormGroup。我还有以下代码可以重置反应表单中的所有值,但 ng-select 元素除外。
Object.keys(this.myFormGroup.controls).forEach(key => {
const currentControl = this.myFormGroup.controls[key];
if (currentControl == null) {
currentControl.reset();
}
});
我也试过currentControl.patchValue('')and with null,但它不起作用。当我在其中加载错误的“ item”时,ng-select它有一个选定的值“ undefined”,我想在它是时清除这个默认选定的值undefined。这就是我使用== null.
即使你有一个 hacky JavaScript (Vanilla) 解决方案,也要分享它。