您可以使用具有自动完成组件的@ngez库:
https://ngez-platform.firebaseapp.com/#/core/autocomplete
component.html
<input type="text" [ngezAutocomplete]="ngezAutocomplete">
<ngez-autocomplete #ngezAutocomplete>
<ngez-autocomplete-option [value]="value" *ngFor="let value of data">
{{value}}
</ngez-autocomplete-option>
</ngez-autocomplete>
组件技术
import { Component, AfterViewInit, ViewChild } from "@angular/core";
import { NgEzAutocompleteDirective } from "@ngez/core";
import { switchMap } from 'rxjs/operators';
@Component({
selector: 'app',
templateUrl: './app.component.html'
})
export class AppComponent implements AfterViewInit{
data: string[];
@ViewChild(NgEzAutocompleteDirective) autocomplete: NgEzAutocompleteDirective;
ngAfterViewInit() {
this.autocomplete.text$
.pipe(
switchMap(query => this.apiService.getAutoComplete(query))
)
.subscribe(data=> {
this.data = data
})
}
}