小编use*_*292的帖子

Angular Material 自动完成显示 TypeError:无法读取未定义的属性“createEmbeddedView”

我正在尝试使用角度材料自动完成功能。但是当我保持专注时,我开始收到错误:无法读取未定义的属性“createEmbeddedView”

对于我输入的每个字母,我也会收到另一个错误ERROR TypeError: this.autocomplete._setVisibility is not a function有人可以解释一下我的代码有什么问题吗?我是角度的初学者。

在我的 html 上,我有:

<mat-form-field> 
<input formControlName="accId" matAutocomplete="auto" matInput> 
<mat-autocomplete #auto="matAutocomplete">                                                                                                                                                                                                                                                                                                                                                                                         
<mat-option *ngFor="let accId of filteredOptions">  {{accId}}  
</mat-option>                                                                                                                                                                                                                                    
</mat-autocomplete>
</mat-form-field> 
Run Code Online (Sandbox Code Playgroud)

我的 .ts 文件:

 filteredOptions: Observable<string[]>;
 ngOnInit(): void {    
    this.filteredOptions = this.form.controls['accId'].valueChanges.pipe(startWith(''),map(val => this.filter(val)));
    console.log(this.filteredOptions);
    }

  filter(val: string): string[] {
  console.log("Inside filter...");
  return this.details.listOfAccIds.filter(option =>option.toLowerCase().includes(val.toLowerCase()));
  }
Run Code Online (Sandbox Code Playgroud)

注意:我得到 this.details 作为

Detail {listOfAccIds: Array(3), listOfCodes: Array(2), listOfReasons: Array(3)}
  listOfAccIds:(3) ["altaccId", "altaccIdss2", "altiid33"]
  listOfCodes:(2) ["code1", "code2"]
  listOfReasons:(3) ["reason1", "reason2", "reason3"]
Run Code Online (Sandbox Code Playgroud)

typescript angular-material angular

7
推荐指数
1
解决办法
6896
查看次数

标签 统计

angular ×1

angular-material ×1

typescript ×1