【问题标题】:Angular FormArray Radio reset stateAngular FormArray Radio 重置状态
【发布时间】:2021-10-29 01:48:43
【问题描述】:

我在formArray中移动控件,有什么想法为什么在交换元素时,移动控件的radio-element状态在模板中被重置,但值正确存储在表单中?

例如,https://stackblitz.com/edit/angular-ivy-81figr?file=src%2Fapp%2Fapp.component.ts

【问题讨论】:

  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: angular radio-button angular-forms


【解决方案1】:

请相应更改交换功能;

  public swap(userIndex: number, index1: number, index2: number): void {
    const devices = this.getDeviceArray(userIndex);
    if (index2 > 0 && index1 < devices.controls.length - 1) {
      let v1 = devices.controls[index1].value;
      let v2 = devices.controls[index2].value;
      devices.controls[index2].setValue(v1);
      devices.controls[index1].setValue(v2);
      devices.updateValueAndValidity();
    }
  }

【讨论】:

    猜你喜欢
    • 2021-01-15
    • 2019-01-31
    • 2021-02-04
    • 2019-05-06
    • 2020-11-24
    • 1970-01-01
    • 2017-09-06
    • 1970-01-01
    • 2017-04-17
    相关资源
    最近更新 更多