Cap*_*das 20 angular-material angular
我在angular的自动完成示例中收到此错误.这是代码:
ngOnInit() {
this.filteredOptions = this.myControl.valueChanges
.pipe(
startWith(''),
map(val => this.filter(val))
);
}
Run Code Online (Sandbox Code Playgroud)
错误是在startWith上生成的.我在第二个val也遇到了错误.它说:
"{}"类型的参数不能分配给"string"类型的参数
功能是:
filter(val: string): string[] {
return this.options.filter(option =>
option.toLowerCase().indexOf(val.toLowerCase()) === 0);
}
Run Code Online (Sandbox Code Playgroud)
提示: 混合控件或导入有一些东西.我不确定,但是当我创建一个新组件时,一切正常.
小智 59
我只是有同样的问题,事实证明我是从错误的目录导入map和startWith.
import {map, startWith} from "rxjs/operators";
Run Code Online (Sandbox Code Playgroud)
使用它来导入map和startWith,它应该工作和编译.
| 归档时间: |
|
| 查看次数: |
7605 次 |
| 最近记录: |