错误设置表单数组仅带来第一个值

时间:2019-08-09 23:25:38

标签: forms angular2-forms formarray

我找不到在表单中设置值的问题。它只为我带来第一个值,错误是ERROR错误:无法在索引1处找到表单控件 在FormArray._throwIfControlMissing。有谁知道正确的方式是什么?

在我的组件中

  public setValueForm(): void {

const values = {
  '_id': this.priceList._id,
  'name': this.priceList.name,
  'percentage' : this.priceList.percentage,
  'allowSpecialRules' : this.priceList.allowSpecialRules,
  'rules' : this.priceList.rules || []
};

this.priceListForm.setValue(values);
}

和我的html

<div class="row tab-content">
          <div formArrayName="rules" *ngFor="let rule of priceListForm.get('rules').controls; let i = index;">
            <div [formGroupName]="i">
              <div class="row">
                <div class="form-group col-md-4">
                  <label for="category" class="control-label">Rubro:</label>
                  <select class="form-control" formControlName="category">
                    <option *ngFor="let category of categories"
                            [value]="category._id"
                            [disabled]="readonly">
                            {{category.description}}
                    </option>
                  </select>
                </div>
                <div class="form-group col-md-4">
                  <label for="make" class="control-label">Marca</label>
                  <select class="form-control" formControlName="make">
                    <option *ngFor="let make of makes"
                            [value]="make._id"
                            [disabled]="readonly">
                            {{make.description}}</option>
                  </select>
                </div>
                <div class="form-group col-md-3">
                  <label for="percentage" class="control-label">Porcentaje:</label>
                  <div class="input-group">
                    <input type="number" class="form-control" formControlName="percentage" name="percentage" id="percentage" [readonly]="readonly"/>
                  </div>
                  <div *ngIf="formErrors.percentage" class="alert alert-danger">
                    {{ formErrors.percentage }}
                  </div>
                </div>
                <div class="col-md-1">                      
                    <label class="control-label">Acción:</label>
                    <button type="button" class="btn btn-success btn-sm" (click)="addRule()">
                        <i class="fa fa-plus"></i>
                    </button>
                    <button type="button" class="btn btn-danger btn-sm" (click)="deleteRule(i)">
                        <i class="fa fa-trash-o"></i>
                    </button>
                </div>

              </div>
            </div>  
          </div>
        </div>

1 个答案:

答案 0 :(得分:0)

已解决

fig = go.Figure(
    layout={
        "xaxis": {"range": (-0.25, 0.75),
        "tickvals": [-0.25, 0.25, 0.75]
    }
)
fig.add_trace(
    go.Heatmap(
        x=[0, 0, 0],
        y=[2, 4, 6],
        z=[-1, 1, 0],
        name="Name A",
    )
)
fig.add_trace(
    go.Heatmap(
        x=[0.5, 0.5, 0.5],
        y=[6.1, 6.4, 6.7],
        z=[-1, 1, 2],
        name="Name B",
    )
)
fig.show()