/
githubmirror
/
components
Обзор
Документация
Войти
/
githubmirror
/
components
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/components-examples/material/autocomplete/autocomplete-plain-input/autocomplete-plain-input-example.ts
37 строк
1 KB
Kristiyan Kostadinov
docs: fix strict property initialization errors
17 дек 2025, 15:53
17 дек 2025, 15:53
b4fe00f
Код
Авторство
О чём код?
import {Component} from '@angular/core'; import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms'; import {Observable} from 'rxjs'; import {startWith, map} from 'rxjs/operators'; import {AsyncPipe} from '@angular/common'; import {MatAutocompleteModule} from '@angular/material/autocomplete'; /** * @title Plain input autocomplete */ @Component({ selector: 'autocomplete-plain-input-example', templateUrl: 'autocomplete-plain-input-example.html', styleUrl: 'autocomplete-plain-input-example.css', imports: [FormsModule, MatAutocompleteModule, ReactiveFormsModule, AsyncPipe], }) export class AutocompletePlainInputExample { control = new FormControl(''); streets: string[] = ['Champs-Élysées', 'Lombard Street', 'Abbey Road', 'Fifth Avenue']; filteredStreets: Observable<string[]>; constructor() { 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, ''); } }