对于使用离子框架生成动态形式输入“添加更多”按钮?(“Add More” button for ge

2019-10-24 02:58发布

我如何能实现添加更多的表单输入样的功能使用离子框架和angularjs?

应该是这样的 -

http://bootsnipp.com/snippets/featured/dynamic-form-fields-add-amp-remove-bs3

Answer 1:

只需定义具有输入通过他们显示阵列,并且循环:

$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



文章来源: “Add More” button for generating dynamic form inputs using ionic framework?