0
votes

I move the controls inside the formArray, have any ideas why when swap elements, the state of the radio-element of the moved control is reset in the template, but the value is stored in the form correctly?

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

1
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. - Community

1 Answers

1
votes

please change the swap function accordingly;

  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();
    }
  }