MatTable与formArray更新后不刷新

问题描述

我有一个带有formarray“ customersOrdersProductTable”的可编辑matTable。当我发送包含此formarray的表单时,我正在获取此formarray的数据,并将其推到matTable中。但是我有一些麻烦,因为:

  1. matTable中的数据未刷新为接收到的数据
  2. matTable字段中的验证程序停止工作

此外,当我第一次打开坞站时,一切都很好。当我第二次调用函数调用请求数据(getProductsTable)的函数时,就会出现麻烦。

如果我在查询之前放置control.clear()-一切都很好-matTable正在刷新并且验证器工作了,但是matTable在获取数据后闪烁。

Approximate example of problem on stackblitz

getProductsTable(){
    let ProductsTable: CustomersOrdersProductTable[]=[];
    const control = <FormArray>this.formBaseinformation.get('customersOrdersProductTable');
    //control.clear(); if it here - everything is works fine,but matTable is blinking after getting the data.
    this.http.get('/api/auth/getCustomersOrdersProductTable?id='+this.id)
        .subscribe(
            data => { 
                control.clear(); // if it here - matTable is not blinking but i have troubles that i described
                ProductsTable=data as any;
                if(ProductsTable.length>0){
                  ProductsTable.forEach(row=>{
                    control.push(this.formingProductRowFromApiResponse(row));
                  });
                }
               
            },error => console.log(error)
        );
  }

形成matTable的行:

  formingProductRowFromApiResponse(row: CustomersOrdersProductTable) {
    return this._fb.group({
      id: new FormControl (row.id,[]),row_id: [this.getRowId()],product_id: new FormControl (row.product_id,customers_orders_id: new FormControl (+this.id,name: new FormControl (row.name,product_count: new FormControl (row.product_count,[Validators.required,Validators.pattern('^[0-9]{1,7}(?:[.,][0-9]{0,3})?\r?$'),ValidationService.countMoreThanZero]),edizm: new FormControl (row.edizm,edizm_id:  new FormControl (row.edizm_id,product_price:  new FormControl (row.product_price,2})?\r?$'),ValidationService.priceMoreThanZero]),product_price_of_type_price: new FormControl (row.product_price,product_sumprice: new FormControl (row.product_sumprice,available:  new FormControl ((row.total)-(row.reserved),price_type:  new FormControl (row.price_type,price_type_id: [row.price_type_id],nds:  new FormControl (row.nds,nds_id: new FormControl (row.nds_id,reserve:  new FormControl (row.reserve,reserved:  new FormControl (row.reserved,total: new FormControl (row.total,priority_type_price: new FormControl (row.priority_type_price,department_id: new FormControl (row.department_id,department: new FormControl (row.department,shipped:  new FormControl (row.shipped,});
  }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...