TypeError:无法读取Object.eval角度为6的undefined属性“ selected”

时间:2019-08-23 12:18:59

标签: c# asp.net-web-api angular6 angular7

我正在尝试删除产品。但是此错误显示在我的控制台上。 这是我的HTML

<tr *ngFor="let p of products; let i = index;">
    <td><input [(ngModel)]="checked[i].selected" type="checkbox" name="selectproduct" value="{{p.productId}}"></td>
    <td>{{p.productCode}}</td>
    <td>{{p.productName}}</td>
    <td>{{p.productDes}}</td>
    <td>{{p.flag}}</td>
    <td>{{p.price}}</td>
</tr>

这是我的component.ts文件

getSelected() {
    let result = this.checked.filter((ch) => { return ch.selected })
      .map((ch) => { return ch.value });
    return (result);
  }

  deleteProducts(productids = this.getSelected()) {
    this.rest.deleteProducts(productids).subscribe((data: {}) => {
    });
    debugger;
    this.getProducts();
  }

这是我的服务。

deleteProducts(productIds): Observable<any> {
    return this.http.post<any>(endpoint + 'Delete', productIds, httpOptions).pipe(
      map(this.extractData));
  }

1 个答案:

答案 0 :(得分:0)

请确保您在检查的数组中获取值。请检查将值分配给检查后的数组的位置以及该数组是否正在填充。

这里的错误表明您要循环的数组为空,并且checked [i]未定义。

相关问题