【问题标题】:how to fix error TS2769: No overload matches this call如何修复错误 TS2769:没有重载匹配此调用
【发布时间】:2020-09-13 05:32:55
【问题描述】:

我是角度方面的新手... 我收到以下代码的异常,对此我感到很沮丧。

错误信息:

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

这是我的课:

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

这是打字稿:

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))
  );
}

这是我的html:

<mat-form-field>
  <input type="text" placeholder=" עיר יעד" aria-label="Number" matInput formControlName="destinationName" [matAutocomplete]="auto">
  <mat-autocomplete autoActiveFirstOption #auto="matAutocomplete">
    <mat-option *ngFor="let cityDestination of cities | async" [value]="cityDestination.cityId">
      {{cityDestination.cityName}}
    </mat-option>
  </mat-autocomplete>

【问题讨论】:

    标签: html angular typescript forms angular-material


    【解决方案1】:

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

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

    所以您应该删除异步管道或将其绑定到像可观察对象这样的异步对象

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多