I'm using angular 5 and material 2.
In ts file, I have this proeperty:
filteredOptions: Observable<any[]>;
This property is going to have an array of values to show in the autocomplete field.
[{
id:'1', name: 'teste 1'},
{id:'2', name: 'teste 2'},
{id:'3', name: 'teste 3'
}]
This array of values come from the database and it is going to be shown after the user type something.
html file:
## <form class="example-form">
## <mat-form-field class="example-full-width">
## <input type="text" placeholder="Assignee" aria-label="Assignee" matInput [formControl]="myControl" [matAutocomplete]="auto">
## <mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
## <mat-option *ngFor="let option of filteredOptions | async" [value]="option">
## {{ option.name }}
## </mat-option>
## </mat-autocomplete>
## </mat-form-field>
## </form>
ts file example:
this.filteredOptions = Observable<any[]>;
ngOnInit() {
this.filteredOptions = this.myControl.valueChanges
.pipe(
startWith({}),
map(getArrayOfValue(val))
);
}
// it is going to call an api to get the array of values to be shown in the field
getArrayOfValue(val): Observable<any[]> {
const url = this.ROOT_URL + 'veiculo/' + val;
return this.http.get<any[]>(url);
}
This code give me an error
ERROR in src/app/oficina/cadastro/veiculo/veiculo.component.ts(55,5): error TS2322: Type 'Observable>' is not assignable to type 'Observable'. Type 'Observable' is not assignable to type 'any[]'. Property 'includes' is missing in type 'Observable'