我使用的角度ui-bootstrap typeahead,我想使用它作为一种方式来拾取许多选择,所以我需要得到选择的值,当selectMatch方法启动,但我不能找到如何做那在我的控制器
<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">
如果我观看选择的值,我每次按下一个键时都有变化…
scope.$watch('selected',function(newValue,oldValue) {... });
我得到的方法selectMatch是一个被调用时,用户按enter或单击列表,但我不知道如何有一个回调的那个…
谢谢 !
现在有更好的方法这样做。
A new callback method has been added
在控制器文件中添加如下内容:
$scope.onSelect = function ($item,$model,$label) { $scope.$item = $item; $scope.$model = $model; $scope.$label = $label; };
在视图中添加以下内容:
<input type="text" ng-model="selected" typeahead="state for state in states | filter:$viewValue" typeahead-editable="false" typeahead-on-select="onSelect($item,$label)"/>
有关详细信息,请参阅typeahead spec(搜索onSelect)。
检查以下网址是否有帮助
http://www.techguides.in/how-to-create-autocomplete-using-angularjs-ui/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。