如果其他输入已填充,如何动态添加新输入 角度
How to dynamically add a new input if other are filled Angular
我有三个输入:
<input type="text" class="form-control" id="friend-email-input" placeholder="Email" />
<input type="text" class="form-control" id="friend-email-input" placeholder="Email" />
<input type="text" class="form-control" id="friend-email-input" placeholder="Email" />
如果这三个输入和以前的输入被填充,如何添加新输入?我正在使用角度路线,我宁愿使用角度。
谢谢。
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
<input type="text" class="form-control" ng-model="field1" placeholder="Email" />
<input type="text" class="form-control" ng-model="field2" placeholder="Email" />
<input type="text" class="form-control" ng-model="field3" placeholder="Email" />
<input ng-show="field1.length && field2.length && field3.length" type="text" class="form-control" ng-model="field4" placeholder="Email" />
</div>
为每个输入分配一个模型,然后使用 ng-show 仅在模型长度为真(即:非零(时显示第 4 个输入。
跟踪
所需的所有输入,从
$scope.inputs = [{value: ""}, {value: ""}, {value: ""}];
在您的模板中,您将迭代此数组以显示 yoou 的输入
<div ng-app="main" ng-controller="MainController">
<div ng-repeat="input in inputs track by $index">
<input type="text" class="form-control" placeholder="Email" ng-model="input.value"/>
<button ng-click="remove($index)">Remove</button>
</div>
<button ng-click="addInput()">Add Input</button>
</div>
因此,当单击输入的删除按钮时,如果存在超过 3 个输入,则该输入将被删除
如果按下添加输入按钮,我们将附加带有删除按钮的输入文本
$scope.remove = function(index){
if($scope.inputs.length > 3){
$scope.inputs.splice(index, 1);
}
}
$scope.addInput = function(){
$scope.inputs.push({value: ""})
}
下面是一个示例代码笔
相关文章:
- Highcharts:根据表单输入动态显示数据
- 如何根据两个不同的输入动态设置链接的路径
- 使用用户输入动态转换数据(Highcharts,JavaScript,Django)
- 基于文本输入动态更改图片
- 如何为jQuery帖子输入动态数据参数
- 根据用户表单输入动态生成 SQL 语句
- 使用单选按钮将文本输入动态添加到列表中
- 如何将外部输入动态注入 SlimerJS 脚本
- 根据用户输入动态设置高图表尾行选项
- 如何根据输入动态形成字符串
- 将用户输入动态地附加到<script src=“">来自Java Script中的文本框
- 使用其他输入动态添加和删除输入
- Rails根据用户输入动态更新View
- 在Powerpoint中根据用户输入动态更改幻灯片
- 使用用户输入动态创建表
- 从输入动态添加选项
- 根据用户输入动态创建HTTP链接
- 如何检测输入动态变化时的变化
- Angular2使用输入动态添加到表单模型中
- 禁用按钮和输入动态名称