如何使用ionic framework和angularjs实现Add More表单输入类型的功能?
应该是这样的 -
http://bootsnipp.com/snippets/featured/dynamic-form-fields-add-amp-remove-bs3
答案 0 :(得分:7)
只需使用输入定义一个数组,然后循环显示它们:
$scope.inputs = [
{ value: null }
];
$scope.addInput = function () {
$scope.inputs.push({ value: null });
}
$scope.removeInput = function (index) {
$scope.inputs.splice(index, 1);
}
在你看来:
<div ng-repeat="input in inputs">
<input type="text"
ng-model="input.value" />
<button ng-if="$index == inputs.length - 1"
ng-click="addInput()">+</button>
<button ng-if="$index != inputs.length - 1"
ng-click="removeInput($index)">-</button>
</div>