import {Component, OnInit} from '@angular/core'; import {FormControl} from '@angular/forms'; import {Observable} from 'rxjs'; import {startWith, map} from 'rxjs/operators'; /** * @title Plain input autocomplete */ @Component({ selector: 'autocomplete-plain-input-example', templateUrl: 'autocomplete-plain-input-example.html', styleUrls: ['autocomplete-plain-input-example.css'], }) export class AutocompletePlainInputExample implements OnInit { control = new FormControl(); streets: string[] = ['Champs-Élysées', 'Lombard Street', 'Abbey Road', 'Fifth Avenue']; filteredStreets: Observable; ngOnInit() { this.filteredStreets = this.control.valueChanges.pipe( startWith(''), map(value => this._filter(value)) ); } private _filter(value: string): string[] { const filterValue = this._normalizeValue(value); return this.streets.filter(street => this._normalizeValue(street).includes(filterValue)); } private _normalizeValue(value: string): string { return value.toLowerCase().replace(/\s/g, ''); } }