mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
docs(chips): use consistent data structure in autocomplete example (#11175)
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
*ngFor="let fruit of fruits"
|
||||
[selectable]="selectable"
|
||||
[removable]="removable"
|
||||
(remove)="remove(fruit)">
|
||||
{{fruit.name}}
|
||||
(removed)="remove(fruit)">
|
||||
{{fruit}}
|
||||
<mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
|
||||
</mat-chip>
|
||||
<input
|
||||
|
||||
@@ -26,14 +26,15 @@ export class ChipsAutocompleteExample {
|
||||
filteredFruits: Observable<any[]>;
|
||||
|
||||
fruits = [
|
||||
{ name: 'Lemon' },
|
||||
'Lemon',
|
||||
];
|
||||
|
||||
allFruits = [
|
||||
'Orange',
|
||||
'Strawberry',
|
||||
'Lime',
|
||||
'Apple',
|
||||
'Lemon',
|
||||
'Lime',
|
||||
'Orange',
|
||||
'Strawberry'
|
||||
];
|
||||
|
||||
@ViewChild('fruitInput') fruitInput: ElementRef;
|
||||
@@ -50,7 +51,7 @@ export class ChipsAutocompleteExample {
|
||||
|
||||
// Add our fruit
|
||||
if ((value || '').trim()) {
|
||||
this.fruits.push({ name: value.trim() });
|
||||
this.fruits.push(value.trim());
|
||||
}
|
||||
|
||||
// Reset the input value
|
||||
@@ -73,7 +74,7 @@ export class ChipsAutocompleteExample {
|
||||
}
|
||||
|
||||
selected(event: MatAutocompleteSelectedEvent): void {
|
||||
this.fruits.push({ name: event.option.viewValue });
|
||||
this.fruits.push(event.option.viewValue);
|
||||
this.fruitInput.nativeElement.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user