Skip to content

Commit f1a35b4

Browse files
lekhmanruscrisbeto
authored andcommitted
docs(material/list): single selection example (#31990)
- Revert single selection example from #29348 close #31989 (cherry picked from commit 38ac513)
1 parent e43dcab commit f1a35b4

File tree

4 files changed

+16
-34
lines changed

4 files changed

+16
-34
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
<p>
88
Option selected: {{shoesControl.value ? shoesControl.value[0] : 'None'}}
99
</p>
10-
</form>
10+
</form>

src/components-examples/material/list/list-single-selection-reactive-form/list-single-selection-reactive-form-example.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ interface Shoes {
66
value: string;
77
name: string;
88
}
9+
910
/**
1011
* @title List with single selection using Reactive forms
1112
*/
1213
@Component({
1314
selector: 'list-single-selection-reactive-form-example',
14-
templateUrl: 'list-single-selection-form-example.html',
15+
templateUrl: 'list-single-selection-reactive-form-example.html',
1516
imports: [MatListModule, FormsModule, ReactiveFormsModule],
1617
})
1718
export class ListSingleSelectionReactiveFormExample {
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
<form [formGroup]="form">
2-
<mat-selection-list #shoesList [formControl]="shoesControl" name="shoes" [multiple]="false">
3-
@for (shoe of shoes; track shoe) {
4-
<mat-list-option [value]="shoe.value">{{shoe.name}}</mat-list-option>
5-
}
6-
</mat-selection-list>
7-
<p>
8-
Option selected: {{shoesControl.value ? shoesControl.value[0] : 'None'}}
9-
</p>
10-
</form>
1+
<mat-selection-list #shoes [multiple]="false">
2+
@for (shoe of typesOfShoes; track shoe) {
3+
<mat-list-option [value]="shoe">{{shoe}}</mat-list-option>
4+
}
5+
</mat-selection-list>
6+
7+
<p>
8+
Option selected: {{shoes.selectedOptions.hasValue() ? shoes.selectedOptions.selected[0].value : 'None'}}
9+
</p>
Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
11
import {Component} from '@angular/core';
2-
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
32
import {MatListModule} from '@angular/material/list';
4-
interface Shoes {
5-
value: string;
6-
name: string;
7-
}
3+
84
/**
9-
* @title List with single selection using Reactive Forms
5+
* @title List with single selection
106
*/
117
@Component({
128
selector: 'list-single-selection-example',
139
templateUrl: 'list-single-selection-example.html',
14-
imports: [MatListModule, FormsModule, ReactiveFormsModule],
10+
imports: [MatListModule],
1511
})
1612
export class ListSingleSelectionExample {
17-
form: FormGroup;
18-
shoes: Shoes[] = [
19-
{value: 'boots', name: 'Boots'},
20-
{value: 'clogs', name: 'Clogs'},
21-
{value: 'loafers', name: 'Loafers'},
22-
{value: 'moccasins', name: 'Moccasins'},
23-
{value: 'sneakers', name: 'Sneakers'},
24-
];
25-
shoesControl = new FormControl();
26-
27-
constructor() {
28-
this.form = new FormGroup({
29-
clothes: this.shoesControl,
30-
});
31-
}
13+
typesOfShoes: string[] = ['Boots', 'Clogs', 'Loafers', 'Moccasins', 'Sneakers'];
3214
}

0 commit comments

Comments
 (0)