title: What is the ideal way to sort a FormArray object in Angular 2+?
body: <p>I have a formArray which consist of multiple form groups. I need to sort the array dynamically based on a boolean field present in each of the form group in the array. </p>
  
  <p>The boolean field is a checkbox and at any given point of time only one checkbox can be checked (mimics radio button). So when a checkbox is clicked I need to sort the formArray based on the one that is selected. </p>
  
  <p>I know the documentation suggests not to mess with the AbstractControls[] present in the formArray, so what would be the ideal way to dynamically sort the array ?</p>
  
  <p>I have tried to slice the array and set the controls back into the formArray but I keep getting an error "<strong>Must supply a value for form control with name: 'primaryIndicator'.</strong>"</p>
  
  <pre><code>const abstractControls = this.formArray.controls
            .slice()
            .sort((a, b) =&gt; {
              return (a as FormGroup).get('primaryIndicator').value ? -1 : (b as FormGroup).get('primaryIndicator').value ? 1 : 0;
            });
          this.formArray.setValue(abstractControls);
  </code></pre>
  
  <p>If this is not the right way, what would be the best approach to solve such a scenario ?</p>