在表格内输入带有Angular中的动态列和行的

问题描述

我有一个带有两个输入columnasfilascolumnsrows)的表单

enter image description here

并通过这两个数据创建一个nxn表,并用表中的随机数据填充它们:

enter image description here

我还希望可以选择输入手动数据,如下所示:

enter image description here

但是由于我是动态添加行和列的,所以我不知道如何为该表中的每个输入创建标识符并将其通过NgForm发送到方法

这是我如何处理随机数据的方法

    <form (ngSubmit)="ejecutarModelos(g.value)" #g="ngForm" *ngIf="mostrarMatriz && datos.manual">
  <h4 class="display-6">Matriz Manual:</h4>
  <table class="table table-bordered jumbotron">
    <thead>
      <tr>
        <th scope="col">#</th>
        <th scope="col" *ngFor="let columna of arrayColumnas">Col. {{columna}}</th>
      </tr>
    </thead>
    <tbody>
      <tr *ngFor="let fila of arrayFilas">
        <th>Fila {{fila}}</th>
        <td *ngFor="let obj of td.arrayRandom">{{obj[fila]}}</td>
      </tr>
    </tbody>
  </table>
</form>

component.ts

 ejecutarRandom(f: NgForm) {

this.resultadoLagrange = f.value.columnas;
let nColumnas = 1 / f.value.columnas;

this.arrayColumnas = [];
this.arrayFilas = [];



for (let index = 1; index <= f.value.filas; index++) {
  this.arrayFilas.push(index);
}

for (let index = 1; index <= f.value.columnas; index++) {
  this.arrayColumnas.push(index);
  let obj = {}

  for (let index = 1; index <= this.arrayFilas.length; index++) {

    let first = index;
    obj[first] = this.getRandom(f.value.rangoMin,f.value.rangoMax);
  }

  this.td.arrayRandom.push(obj)

}
this.td.arrayLagrnage = [...this.td.arrayRandom]
this.metotodoLagrange(this.td.arrayLagrnage,nColumnas);
this.mostrarMatriz = true;

};

解决方法

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

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

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