【发布时间】:2018-03-09 20:58:30
【问题描述】:
我已经在 AngularJS 中动态地添加和删除输入文本字段。这是我的代码:
我的 HTML
<div class="form-group">
<label for="hobbies">Hobbies</label>
<span ng-repeat="hobby in hobbies track by $index">
<div class="form-group">
<input type='text' ng-model='hobbies[$index]' class="form-control pull-right"/>
<button ng-click = "addHobby()" ng-show="$last">+</button>
<button ng-click = "removeHobby($index)" ng-show="hobbies.length > 1">-</button>
</div>
</span>
</div>
角度控制器
$scope.hobbies = [''];
$scope.addHobby = function() {
$scope.hobbies.push('');
}
$scope.removeHobby = function(index) {
if(index >= 0){
$scope.hobbies.splice(index, 1);
}
}
在此,当我点击+ 按钮时,如何验证空文本字段?
【问题讨论】:
-
在 addHobby 函数中,您可以添加对空字段的检查
标签: javascript jquery angularjs validation