mirror of
https://github.com/richard-loafle/fuse-angular.git
synced 2025-04-18 14:22:35 +00:00
31 lines
926 B
TypeScript
Executable File
31 lines
926 B
TypeScript
Executable File
import {Component, OnInit} from '@angular/core';
|
|
import {FormControl} from '@angular/forms';
|
|
import {Observable} from 'rxjs';
|
|
import {map, startWith} from 'rxjs/operators';
|
|
|
|
/**
|
|
* @title Highlight the first autocomplete option
|
|
*/
|
|
@Component({
|
|
selector: 'autocomplete-auto-active-first-option-example',
|
|
templateUrl: 'autocomplete-auto-active-first-option-example.html',
|
|
styleUrls: ['autocomplete-auto-active-first-option-example.css']
|
|
})
|
|
export class AutocompleteAutoActiveFirstOptionExample implements OnInit {
|
|
myControl: FormControl = new FormControl();
|
|
options = ['One', 'Two', 'Three'];
|
|
filteredOptions: Observable<string[]>;
|
|
|
|
ngOnInit() {
|
|
this.filteredOptions = this.myControl.valueChanges.pipe(
|
|
startWith(''),
|
|
map(val => this.filter(val))
|
|
);
|
|
}
|
|
|
|
filter(val: string): string[] {
|
|
return this.options.filter(option => option.toLowerCase().indexOf(val.toLowerCase()) === 0);
|
|
}
|
|
|
|
}
|