如何在添加按钮上增加输入框

时间:2017-05-05 06:00:19

标签: javascript jquery html angular

我想增加输入框, 它的增量和拼接但问题是当我在一个盒子中输入值时,在另一个盒子中替换它。我认为它是由于ngModel。任何人都可以帮助我.Thnaks。

    <div class="form-group row text-right" *ngFor='let row of vipInput'>
    <label class="col-sm-3 form-control-label m-t-5" for="password-h-f"></label>
    <div class="col-sm-9 form-control-label m-t-5" for="password-h-f">
        <div class="row">
            <div class="col-sm-9" >
                <input class="form-control"  [(ngModel)]="data.vipInput" id="email" type="email">
            </div>
            <div class="col-sm-3">
                <button class="btn btn-danger" (click)="removeVipInputs(index)">Remove</button>
            </div>
        </div>
    </div>
</div> 
     <button type="button" class="btn btn-secondary" (click)="vipInputIncrement('val')">
             <i class=" fa fa-plus"></i>
     </button>

我的,(我正在使用angular2)

 vipInputIncrement(val) {
   this.vipInput.push({'val':''});
}
removeVipInputs(k) {
  this.standardInput.splice(k,1);
}

1 个答案:

答案 0 :(得分:0)

你的ng模型应该是这一行的内容,

    <div class="form-group row text-right" *ngFor='let row of vipInput'>
    <label class="col-sm-3 form-control-label m-t-5" for="password-h-f"></label>
    <div class="col-sm-9 form-control-label m-t-5" for="password-h-f">
        <div class="row">
            <div class="col-sm-9" >
                <input class="form-control"  [(ngModel)]="row.val" id="email" type="email">
            </div>
            <div class="col-sm-3">
                <button class="btn btn-danger" (click)="removeVipInputs(index)">Remove</button>
            </div>
        </div>
    </div>
</div> 

我认为它应该是row.val,但您可以决定要展示的内容