HTML:
<div ng-repeat="p in postBack" style="overflow: hidden;">
<div class="form-group" style="width: 47.5%;float: left;">
<input type="text" class="form-control" name="firstName{{$index}}"/>
</div>
<div class="form-group" style="width: 47.5%;float: left;margin-bottom: 0px">
<input type="text" class="form-control" name="lastName{{$index}}" />
</div>
<button style="top: 36px;right: 0px;color: #9960a7;opacity: inherit;position: relative;" type="button" ng-click="addGuestName(postBack.length)" ng-show="$index==0">+</button>
<button style="top: 35px;right: 0px;color: #9960a7;opacity: inherit;position: relative;" type="button" ng-click="deleteGuestName($index)" ng-show="$index!=0">×</button>
</div>
JS:
$scope.postBack = [{}];
$scope.addGuestName = function(idx){
var postBack={};
$scope.postBack.push(postBack);
};
$scope.deleteGuestName = function(idx){
$scope.postBack.splice(idx,1);
};
就OK啦。就利用ng-repeat数组。谢谢
可以参考https://blog.csdn.net/weixin_36185028/article/details/72866963