更改Mat Autocomplete Angular 5的默认行为

时间:2018-09-17 13:15:44

标签: angular

我正在尝试实现自动填充功能。每当用户在文本框字段中输入$时,我都想显示自动完成选项。但是按照默认功能,仅在输入开始时,自动完成功能才会打开。我想在任何位置打开它。这是我尝试过的:

search(val:string) {
this.filteredOptions = this.menuForm.controls.notificationText.valueChanges.
pipe(startWith(''),
map(value=>value.includes('${')?this.filter(value):[]));}

filter(val:string):string[]{
return this.searchResult.filter
(option => option.toLowerCase().
indexOf(val.toLowerCase())===0);}

<mat-form-field floatLabel='never'>
<textarea #textvalue matInput placeholder="Text in English"formControlName="notificationText"(keyup)="search(textvalue.value)"[matAutocomplete]="auto"></textarea>

<mat-autocomplete#auto="matAutocomplete"><mat-option*ngFor="let item of searchResult"[value]="item">{{ item }}</mat-option></mat-autocomplete>
</mat-form-field>

0 个答案:

没有答案