此方法使用了angular的迭代指令ng-repeat,从一个元素的集合里迭代出来显示在视图上。
看代码(略去的css样式)
<ul>
<li ng-click="add()">
<i class="icon-plus"></i>
<span>Add New Postback</span>
</li>
<li class="s-pbAddUrl" ng-repeat="p in postBack track by $index">
<input type="text" placeholder="http|https://...">
<span ng-click="del($index)" ng-show="$index!=0">
<i class="icon-minus"></i>
</span>
</li>
<li>Save Edition</li>
</ul>
在对应的控制器内:
$scope.postBack = [''];
$scope.add = function(){
var postBack='';
$scope.postBack.push(postBack);
};
$scope.del = function(idx){
$scope.postBack.splice(idx,1);
};
下过如下所示;