gpt4 book ai didi

html - ng-blur with uib-typeahead (ui-bootstrap)

转载 作者:行者123 更新时间:2023-11-28 00:47:29 25 4
gpt4 key购买 nike

   <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,但是由于提前输入,如果我使用鼠标选择提前输入建议的选项,ng-blur“认为“我离开了这个领域并用我输入的第一个字母激活了 ng-blur我该如何覆盖它?

最佳答案

不使用 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

关于html - ng-blur with uib-typeahead (ui-bootstrap),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49601221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com