在选择匹配角度UI的引导预输入回调? [英] angular ui-bootstrap typeahead callback on selectMatch?

查看:250
本文介绍了在选择匹配角度UI的引导预输入回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的角度UI自举预输入,我想用它作为一种去接很多选择,所以我需要的时候选择匹配方式推出来获得所选择的价值,但我无法找到如何做到这一点在我的控制器

I'm using the angular ui-bootstrap typeahead and I would want to use it as a way to pick up many choices, so I'd need to get the selected value when selectMatch method is launched but I can't find how to do that in my controller

<div class='container-fluid' ng-controller="TypeaheadCtrl">
<pre>Model: {{selected| json}}</pre>
<input type="text" ng-model="selected" typeahead="state for state in states | filter:$viewValue">

如果我看所选的价值,我每次都得到了变革的关键是pressed ...

If I watch the selected value, I got the change every time a key is pressed...

scope.$watch('selected', function(newValue, oldValue) {... });

我的方法选择匹配是当用户preSS输入或点击列表上,但我不知道该怎么对一个回调被称为一个...

I got that the method selectMatch is the one which is called when the user press enter or click on the list but I don't know how to have a callback on that...

谢谢!

推荐答案

现在有这样做的更好的方法。 新回调方法添加

There is better way of doing this now. A new callback method has been added

在控制文件中添加以下内容:

In controller file add the following:

 $scope.onSelect = function ($item, $model, $label) {
    $scope.$item = $item;
    $scope.$model = $model;
    $scope.$label = $label;
};

在视图中添加以下内容:

In view add the following:

 <input type="text"
        ng-model="selected"
        typeahead="state for state in states | filter:$viewValue"
        typeahead-editable="false"
        typeahead-on-select="onSelect($item, $model, $label)"/>

查看<一个href=\"https://github.com/angular-ui/bootstrap/blob/91ac17c9ed691a99647b66b3f464e3585398be19/src/typeahead/test/typeahead.spec.js#L372\">typeahead SPEC 了解更多的信息(搜索ONSELECT)。

See the typeahead spec for more information (search for onSelect).

检查一下下面的网址帮助
<一href=\"http://www.techguides.in/how-to-create-autocomplete-using-angularjs-ui/\">http://www.techguides.in/how-to-create-autocomplete-using-angularjs-ui/

Check out if the following URLs helps http://www.techguides.in/how-to-create-autocomplete-using-angularjs-ui/

<一个href=\"http://www.techguides.in/how-to-customize-autocomplete-to-display-multiple-columns-using-angularjs-ui-2/\">http://www.techguides.in/how-to-customize-autocomplete-to-display-multiple-columns-using-angularjs-ui-2/

这篇关于在选择匹配角度UI的引导预输入回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆