0
按钮点击我已经编码添加和AngularJS动态删除输入文本字段。这里是我的代码:验证空文本字段,每当我在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功能,您可以添加一个检查空场 –