如何修复错误TS2769:此调用无重载

时间:2020-05-26 12:04:46

标签: html angular typescript forms angular-material

我是新手... 对于以下代码,我会遇到此异常,对此我感到沮丧。

错误消息:

错误TS2769:没有过载与该调用匹配。 最后一次重载给出了以下错误。 类型“ City []”的参数不能分配给类型“ Promise”的参数。 类型“ City []”缺少类型“ Promise”中的以下属性:然后,捕获, [Symbol.toStringTag],最后

这是我的课程:

company

这是typeScript:

export class City{
    cityId:number;
    cityName:string; }

这是我的html:

export class AddFlightComponent implements OnInit {
  cities:City[]=[];
  filteredOptionsD: Observable<City[]>;

  addFlightForm:FormGroup=new FormGroup({
    destinationName:new FormControl()
  });

  private _filterD(value: string): City[] {
    const filterValueD = value.toLowerCase();
    return this.cities.filter(option => option.cityName.toLowerCase().indexOf(filterValueD) === 0);
  }

func()
{
  this.filteredOptionsD = this.addFlightForm.controls['destinationName'].
  valueChanges
  .pipe(
    startWith(''),
    map(value => this._filterD(value))
  );
}

1 个答案:

答案 0 :(得分:1)

由于cities既不是承诺,也不是可观察的异步管道,因此无法使用

<mat-option *ngFor="let cityDestination of cities | async" [value]="cityDestination.cityId">

// correct
<mat-option *ngFor="let cityDestination of cities" [value]="cityDestination.cityId">

所以您应该删除异步管道或将其绑定到异步的东西,如可观察的