<div class="form-group">
<label for="Skill1">Skill</label>
<input type="text"
ng-model="vm.skill1"
name="skill1"
uib-typeahead="skill for skill in vm.skills | filter:$viewValue"
class="form-control typeahead"
ng-blur="vm.checkSkills(vm.skill1)"
placeholder=""
required>
</div>
我的环境是AngularJs,我只是在用户离开此字段时尝试使用ng-blur,但是由于输入类型,如果我使用鼠标选择typeahead建议的选项,ng-blur &#34;认为&#34;我离开了场地,只用我所选择的第一个字母激活了ng-blur 我怎样才能覆盖这个?
答案 0 :(得分:1)
不使用ng-blur
,而是使用
typeahead-on-select="checkSkills($item,$model,$label)"
HTML
<input type="text" ng-model="skill1" uib-typeahead="skill for skill in skills | filter:$viewValue" class="form-control typeahead" typeahead-on-select="checkSkills($item,$model,$label)"
<强> JS 强>
$scope.checkSkills = function(item, model, label){
if(model){
//your validation logic goes here
// console.log (" Check skill, correctly set ", (item), model , label);
}
}
Plunker示例:https://plnkr.co/edit/7N8TU2?p=preview