微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MatTable与formArray更新后不刷新

如何解决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 举报,一经查实,本站将立刻删除。