I'm trying to use the angular material drag and drop component to reorder a list of basic radio inputs.
When the page loads, the correct radio input is checked. My problem is that, when I reorder the checked item in the list using the [Grab] handle, the radio selection appears to reset and I can't figure out how to persist the selection.
The really odd thing to me, is that if this was a checkbox, it'd work fine. So I'm assuming it's something to do with the way I've set up the radio input.
Appreciate any help you're able to offer.
Here's my stackblitz: https://stackblitz.com/edit/angular-2q94xh
app.component.html
<table cdkDropList (cdkDropListDropped)="drop($event)">
<tr *ngFor="let selection of content" cdkDrag>
<td>
<div class="grab" cdkDragHandle>[Grab]</div>
</td>
<td>
<input
[id]="selection.id"
type="radio"
name="radio"
[checked]="selection.selected"
>
</td>
<td>{{ selection.selected }}</td>
</tr>
</table>
app.component.ts
import { Component } from '@angular/core';
import {CdkDragDrop, moveItemInArray, transferArrayItem, CdkDrag} from '@angular/cdk/drag-drop';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
drop(event: CdkDragDrop<string[]>) {
moveItemInArray(this.content, event.previousIndex, event.currentIndex);
}
content = [
{
"id": "1",
"selected": false
},
{
"id": "2",
"selected": false
},
{
"id": "3",
"selected": true
}
]
}