大佬教程收集整理的这篇文章主要介绍了以编程方式选择AngularJS Typeahead选项,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想象的是这样的:
$scope.SearchItems = function (term) { return $http.get('api/Items/Search',{ params: { term: term } }).then(function (responsE) { if (response.data.length == 1 && response.data[0].Code == term) { // Somehow inform typeahead control to SELEct response.data[0] } return response.data; }); };
$promise.then(function(res) { angular.forEach(res,function(item,key) { // if we have an exact match if (item.title === term) { // update model $scope.src = item; // find item in dropdown var elm = '[id*=option-' + key + ']'; var opt = angular.element(document.querySELEctorAll(elm)); //call click handler outside of digest loop $timeout(function() { opt.triggerHandler('click'); },0); } }); // return async results return res; });
基本上我们只是手动更新我们的模型,在我们的下拉列表中找到元素,然后触发’click’处理程序.确保将$timeout()中的triggerHandler调用设置为零,否则您将获得$rootScope:inprog错误,因为@L_772_14@已在进行中.
以上是大佬教程为你收集整理的以编程方式选择AngularJS Typeahead选项全部内容,希望文章能够帮你解决以编程方式选择AngularJS Typeahead选项所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。