“添加更多"使用离子框架生成动态表单输入的按钮? [英] "Add More" button for generating dynamic form inputs using ionic framework?
本文介绍了“添加更多"使用离子框架生成动态表单输入的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用离子框架和angularjs实现添加更多表单输入"功能?
How can I implement Add More form inputs kind of function using ionic framework and angularjs?
应该是这样-
http://bootsnipp.com/snippets/特色/动态表单字段添加-删除-bs3
推荐答案
只需定义一个带有输入的数组,然后遍历它们以显示:
Just define an array with inputs, and loop through them to display:
$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>
请参见此jsfiddle
这篇关于“添加更多"使用离子框架生成动态表单输入的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文