Angular 角度材质自动完成不工作,未显示错误

Angular 角度材质自动完成不工作,未显示错误,angular,typescript,autocomplete,angular-material,angular-material2,Angular,Typescript,Autocomplete,Angular Material,Angular Material2,我已经实现了我的自动完成,没有错误,一切似乎都正常,但绝对没有发生任何事情。我在输入字段中输入了一些内容,但似乎没有发生任何操作,控制台中没有显示任何内容 HTML 编辑:我已经导入了 import {MatAutocompleteModule} from '@angular/material/autocomplete'; 在我的应用程序模块中 资料的版本- "@angular/material": "^5.0.0-rc.2", 您的.ts 您必须通过以下方式订阅您的myControlval

我已经实现了我的自动完成,没有错误,一切似乎都正常,但绝对没有发生任何事情。我在输入字段中输入了一些内容,但似乎没有发生任何操作,控制台中没有显示任何内容

HTML

编辑:我已经导入了

import {MatAutocompleteModule} from '@angular/material/autocomplete';
在我的应用程序模块中

资料的版本-

"@angular/material": "^5.0.0-rc.2",

您的
.ts

您必须通过以下方式订阅您的
myControl
valueChanges

this.myControl.valueChanges.subscribe(newValue=>{
    this.filteredValues = this.filterValues(newValue);
})
因此,每当表单控件值发生更改时,您都会调用自定义的
filterValues()
方法,该方法应该如下所示:

filterValues(search: string) {
    return this.testValues.filter(value=>
    value.toLowerCase().indexOf(search.toLowerCase()) === 0);
}
因此,您使用
testValues
数组作为基本数组,并在html中使用
filteredValues
数组:

<mat-option *ngFor="let n of filteredValues" [value]="n">
    {{n}}
</mat-option>

{{n}}

筛选不是自动的,您必须使用自定义方法筛选选项。希望有帮助

您是否已将MatAutocompleteModule放入模块导入中?是的,我的模块导入中有MatAutocompleteModule是的,它应该与过滤器一起工作。谢谢你花时间,我试着用你的,但它给了我“找不到名字”和“找不到名字地图”。我是不是错过了一些重要的东西?
filterValues(search: string) {
    return this.testValues.filter(value=>
    value.toLowerCase().indexOf(search.toLowerCase()) === 0);
}
<mat-option *ngFor="let n of filteredValues" [value]="n">
    {{n}}
</mat-option>