首页 > 解决方案 > 如何以角度形式创建多个输入并将其保存到数组中

问题描述

根据选择的人数,我想让用户能够根据选择的人数将所有用户的姓名输入到数组中,如 name = ["people1", "people2"];

<form  [formGroup]="guestList" novalidate>
        <mat-tab-group dynamicHeight #matgroup>

          <mat-tab label="Guest Information">

            <label>Select the number of peope</label>
            <div class="form-group">
              <mat-select name="no" formControlName="no" class="form-control">
                  <mat-option name="no" *ngFor="let number of [1,2,3,4]" [value]="number" >{{number}}</mat-option>
              </mat-select>
            </div>



            <label> People Names</label>
            // **create number of input's depending upon number selected instead of using the array**
            <div class="form-group" *ngFor="let input of [1,2,3,4]">
                  <input type="text" formControlName="Name" class="form-control" [(ngModel)]="input.value">

            </div>


          </mat-tab>
         </mat-tab-group>
</form>

标签: angular

解决方案


推荐阅读