selectMatch 上的 angular ui-bootstrap typeahead 回调? [英] angular ui-bootstrap typeahead callback on selectMatch?
问题描述
我正在使用 angular ui-bootstrap typeahead,我想用它作为选择许多选项的一种方式,所以我需要在 selectMatch 方法启动时获取选定的值,但我找不到如何在我的控制器中做到这一点
<预>型号:{{selected|json}}</pre><input type="text" ng-model="selected" typeahead="state for state in states | filter:$viewValue">如果我查看选定的值,每次按下一个键时我都会得到更改...
scope.$watch('selected', function(newValue, oldValue) {... });
我知道 selectMatch 方法是在用户按 Enter 键或单击列表时调用的方法,但我不知道如何对此进行回调...
谢谢!
解决方案 现在有更好的方法来做到这一点.添加了新的回调方法
在控制器文件中添加以下内容:
$scope.onSelect = function ($item, $model, $label) {$scope.$item = $item;$scope.$model = $model;$scope.$label = $label;};
在视图中添加以下内容:
请参阅typeahead 规范更多信息(搜索 onSelect).
看看以下网址是否有帮助http://www.techguides.in/how-to-create-autocomplete-using-angularjs-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">
If I watch the selected value, I got the change every time a key is pressed...
scope.$watch('selected', function(newValue, oldValue) {... });
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...
Thanks !
解决方案 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)"/>
See the typeahead spec for more information (search for onSelect).
Check out if the following URLs helps
http://www.techguides.in/how-to-create-autocomplete-using-angularjs-ui/
这篇关于selectMatch 上的 angular ui-bootstrap typeahead 回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文