typescript - 角度材料自动完成有此错误“错误错误:ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后已更改。”
问题描述
我想要做的是我的表格将有一个用于插入产品代码的输入字段,并且输入字段也可以搜索产品。
但是当我刷新页面时,会出现错误,请问是什么问题?我是 Angular 9 的新手
HTML
<tr *ngFor="let item of dataSource" cdkDrag cdkDragLockAxis="y">
....
<input class="form-control" [(ngModel)]="item.code" type="text" placeholder="Code" name="Code"
matInput
[formControl]="myControl"
[matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
{{option}}
</mat-option>
</mat-autocomplete>
... <tr>
打字稿
import {FormControl} from '@angular/forms';
import {Observable} from 'rxjs';
import {map, startWith} from 'rxjs/operators';
...
...
dataSource = [
{
index: 1,
name: 'abc',
code: 'abc',
desc: 'abc',
qty: 1,
unit: 'abc',
price: 1.00,
tax: 'abc',
amount: 1
},
{
index: 2,
name: 'abc2',
code: 'abc2',
desc: 'abc2',
qty: 2,
unit: 'abc2',
price: 2.00,
tax: 'abc2',
amount: 2
}];
myControl = new FormControl();
options: string[] = ['One', 'Two', 'Three'];
filteredOptions: Observable<string[]>;
ngOnInit() {
this.filteredOptions = this.myControl.valueChanges
.pipe(
startWith(''),
map(value => this._filter(value))
);
}
private _filter(value: string): string[] {
const filterValue = value.toLowerCase();
return this.options.filter(option => option.toLowerCase().includes(filterValue));
}
解决方案
推荐阅读
- javascript - 如何从 JavaScript 中的 Set 中删除对象
- mysql - 无法重新启动 mysql(有关详细信息,请参阅“systemctl status mysql.service”和“journalctl -xe”。)
- jquery - 从 jquery-1.11.1.js 迁移到 jquery-1.12.4.js
- google-chrome-extension - 如何在不打开空选项卡的情况下从扩展程序启动自定义 URI?
- spring-boot - 使用 JpaRepository 将 protobuf 直接保存为实体
- php - 使用 ajax 序列化文件(图像)并插入查询
- c# - 在数据网格上插入 PersianDate 时出错:无法评估表达式,因为当前线程处于堆栈溢出状态
- c# - 用于显示图像管理器对话框的 Enterprise Architect API
- android - Clang:在 libc++ 中使用 std::Map 时,复制赋值运算符被删除
- ios - UIPickerView 选择将 nil 值发送到新的 ViewController