0

I'm trying to do an autocomplete, but this is throwing this error, what better way to treat? I have this json coming from my database

[{
    'ID': '1',
    'Initials': 'AC',
    'Name': 'Acre'
  },
  {
    'ID': '2',
    'Initials': 'AL',
    'Name': 'Alagoas'
  },
  {
    'ID': '3',
    'Initials': 'AM',
    'Name': 'Amazonas'
  }
]

This component HTML

<mat-form-field class="mr-24" fxFlex="33">
                                <input matInput placeholder="Estado" formControlName="State" [matAutocomplete]="autoState" required>
                                <mat-autocomplete autoActiveFirstOption #autoState="matAutocomplete" [displayWith]="getOptionText" >
                                    <mat-option *ngFor="let state of filteredStateOptions  | async" [value]="state.Name">
                                        {{state.Name}}
                                    </mat-option>
                                </mat-autocomplete>
</mat-form-field>

This my method that I took from the angular site

onStateChanges(): void {
  this.filteredStateOptions = this.clientForm.get('State').valueChanges.pipe(startWith(''), map(value => this.filterStateOptions(value)));
}

filterStateOptions(value): any {
  const filterValue = value.toLowerCase();
  const filteredState = this.states.filter(option => option.Name.toLowerCase().indexOf(filterValue) === 0);
  return filteredState;
}
ahmeticat
  • 1,899
  • 1
  • 13
  • 28
Eliemerson Fonseca
  • 717
  • 3
  • 10
  • 33

0 Answers0