无法在Angular 5中使用FormArray获取输入框

时间:2018-03-26 18:43:40

标签: angular angular5

我的html模板是

    <button (click)="addAdd()">Add Address</button>     
<div formArrayName="address">
    <div *ngFor="let add of personalForm.controls?.user?.address?.controls; let i=index" [formGroupName]="i">
        <div class="panel-heading">
            <span class="glyphicon glyphicon-remove pull-right" *ngIf="personalForm.controls.address.controls.length > 1" (click)="removeAdd(i)"></span>
            <label>Country</label>
            <input type="text" class="form-control" formControlName="country" placeholder="Country"/>
        </div>
    </div>
</div> 

我的Json是

personalData =  {address:[{country: "IN", state: "MH"}, {country: "IN", state: "NA"}], faname: "xyz"}

我无法在html页面中获取输入框我做错了什么? 我想在personalData.address中进行循环,并且需要在输入框中打开现有数据,以及当我点击addAdd()

时我想增加正在处理的数组

1 个答案:

答案 0 :(得分:0)

我错过了用户和地址<div *ngFor="let add of personalForm.controls?.user?.controls?.address?.controls; let i=index" [formGroupName]="i">

之间的控件

并解决了!