Skip to content

Commit 92d27a8

Browse files
authored
docs: clarify value of the form control in the chips-form-control example (#22995)
We recently added an example for chips with a form control. This example should clarify how the chip list can interact with a form control. It seems like it is not quite clear what value the form control represents, or how a chip can be "selected". This has been improved as per this commit. Fixes #22933.
1 parent fafb24d commit 92d27a8

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/components-examples/material/chips/chips-form-control/chips-form-control-example.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
</div>
55

66
<p>
7-
Selected keywords: {{formControl.value}}
7+
<i>Select a focused chip by pressing <code>SPACE</code></i>
88
</p>
99

1010
<mat-form-field class="example-chip-list" appearance="fill">
1111
<mat-label>Video keywords</mat-label>
1212
<mat-chip-list #chipList aria-label="Video keywords" multiple [formControl]="formControl">
1313
<mat-chip
14-
*ngFor="let keyword of keywords"
15-
(removed)="removeKeyword(keyword)">
14+
*ngFor="let keyword of keywords"
15+
[selected]="keyword"
16+
[value]="keyword"
17+
(removed)="removeKeyword(keyword)">
1618
{{keyword}}
1719
</mat-chip>
1820
<input
@@ -21,3 +23,7 @@
2123
(matChipInputTokenEnd)="addKeywordFromInput($event)">
2224
</mat-chip-list>
2325
</mat-form-field>
26+
27+
<p>
28+
<b>The following keywords are selected:</b> {{formControl.value}}
29+
</p>

src/components-examples/material/chips/chips-form-control/chips-form-control-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {MatChipInputEvent} from '@angular/material/chips';
1212
})
1313
export class ChipsFormControlExample {
1414
keywords = new Set(['angular', 'how-to', 'tutorial']);
15-
formControl = new FormControl();
15+
formControl = new FormControl(['angular']);
1616

1717
addKeywordFromInput(event: MatChipInputEvent) {
1818
if (event.value) {

0 commit comments

Comments
 (0)