Angular中的MatAutocomplete在控制台中返回空字符串
创始人
2024-10-31 07:30:30
0

通常是因为Mat Autocomplete没有正确连接到FormControl。可以尝试在FormControl和Mat Autocomplete之间添加[(ngModel)],或者使用[formControl]属性替换[matAutocomplete]属性。

示例代码如下:

HTML模板:

{{ option }}

组件:

import { Component, OnInit } from '@angular/core'; import { FormControl } from '@angular/forms'; import { Observable } from 'rxjs'; import { map, startWith } from 'rxjs/operators';

@Component({ selector: 'app-autocomplete', templateUrl: './autocomplete.component.html', styleUrls: ['./autocomplete.component.css'] }) export class AutocompleteComponent implements OnInit { myControl = new FormControl(); options: string[] = ['Option 1', 'Option 2', 'Option 3']; filteredOptions: Observable;

constructor() { }

ngOnInit() { this.filteredOptions = this.myControl.valueChanges .pipe( startWith(''), map(value => this._filter(value)) ); }

private _filter(value: string): string[] { const filterValue = value.toLowerCase();

return this.options.filter(option => option.toLowerCase().includes(filterValue));

} }

相关内容

热门资讯

推出新举措"wepo... 推出新举措"wepoker国外版透视"wpk透视怎么安装(其实是有辅助app)-哔哩哔哩1、wepo...
有玩家发现"hhpo... 有玩家发现"hhpoker辅助软件是真的么"wepoker辅助分析器(一贯存在有辅助神器)-哔哩哔哩...
今天下午"wepok... 今天下午"wepoker破解器"wepoker开辅助能查到吗(切实真的是有辅助工具)-哔哩哔哩一、w...
近日"hhpoker... 近日"hhpoker辅助器"德普之星怎么设置埋牌(总是真的有辅助神器)-哔哩哔哩1、完成德普之星怎么...
最终"wepoker... 最终"wepoker怎么开辅助"pokemmo内置修改器(竟然是有辅助软件)-哔哩哔哩1、进入游戏-...
透视辅助"wepok... 透视辅助"wepoker软件安装包"wepoker免费脚本咨询(本来存在有辅助辅助器)-哔哩哔哩一、...
据公告内容"wepo... 据公告内容"wepoker的辅助器"epoker透视(原来是有辅助神器)-哔哩哔哩1、进入游戏-大厅...
透视有挂"wepok... 透视有挂"wepoker免费钻石"wpk辅助器是真的吗(都是真的是有辅助软件)-哔哩哔哩1、下载好w...
这一问题亟待解决"约... 这一问题亟待解决"约局吧德州有挂吗"佛手在线大菠萝辅助(竟然有辅助插件)-哔哩哔哩1、下载好佛手在线...
据了解"wepoke... 据了解"wepoker有人用过吗"红龙poker辅助(果然存在有辅助神器)-哔哩哔哩1、操作简单,无...