自动完成功能找不到类型为'object'

时间:2018-10-29 10:08:55

标签: angular autocomplete

我对angular并不陌生,我正在尝试使用本教程中的自动完成功能并适应我的项目:https://material.angular.io/components/autocomplete/overview 问题是在我更改了代码的几种结构后,它变成了一个错误,任何人都可以告诉我我在这里做错了什么。预先感谢。

myControl = new FormControl();
 filteredOptions: Observable<any[]>;
  
   this.configSerivce.getConfig().subscribe( (data:Line)  => {
        this.line=data;
        this.line[this.i].status = false; //added new attribute status
        this.i++;
    });
    
    this.filteredOptions = this.myControl.valueChanges
    .pipe(
      startWith(''),
      map(value => this._filter(value))
    );
    
  private _filter(value: string,line : any): any[] {
    const filterValue = parseInt(value);
    return line.filter(option => option.lineNumber === filterValue);
  }
export interface Line {
    baseVersion?: string;
    netVersion?: number;
    mandator?: string;
    lineNumber?: number;
    shortName?: string;
    name?: string;
    variants?: Array<Variant>;
}
<form class="example-form">
  <mat-form-field class="example-full-width">
    <input type="text"  matInput [formControl]="myControl" [matAutocomplete]="auto">
    <mat-autocomplete #auto="matAutocomplete">
      <mat-option *ngFor="let option of filteredOptions | async" [value]="option.lineNumber">
        {{option.lineNumber}}
      </mat-option>
    </mat-autocomplete>
  </mat-form-field>
</form>

0 个答案:

没有答案