AngularStrap typeahead,如何使用事件回调
AngularStrap typeahead, how to use event callbacks
我正在使用 AngularStrap typeahead,当用户选择项目时需要回调。根据documentation,有一个onSelect
选项,可以提供一个function
,并且:
If provided, this function will be invoked when an item is selected.
……和……
Options can be passed via data-attributes on the directive or as an object hash to configure the service. For data attributes, append the option name to data-, as in data-animation="".
所以我尝试如下使用它:
<input type="text"
class="form-control"
ng-model="selection"
bs-options="item for item in items"
bs-typeahead
data-on-select="onSelect">
并在我的控制器中提供 onSelect()
方法:
$scope.onSelect = function() {
console.log('this never gets called :(');
};
但是,永远不会调用回调。我在这里遗漏了什么吗?
[edit] dfsq 指出它应该是 bs-on-select
,关于图书馆的来源。我刚刚尝试了这个变体,但是事件只被触发一次。我创建了 this Plunker 来说明我的问题; "Number of selection events" 自然应该随着每次选择而递增,但它仍然是 1.
我正在使用 AngularStrap typeahead,当用户选择项目时需要回调。根据documentation,有一个onSelect
选项,可以提供一个function
,并且:
If provided, this function will be invoked when an item is selected.
……和……
Options can be passed via data-attributes on the directive or as an object hash to configure the service. For data attributes, append the option name to data-, as in data-animation="".
所以我尝试如下使用它:
<input type="text"
class="form-control"
ng-model="selection"
bs-options="item for item in items"
bs-typeahead
data-on-select="onSelect">
并在我的控制器中提供 onSelect()
方法:
$scope.onSelect = function() {
console.log('this never gets called :(');
};
但是,永远不会调用回调。我在这里遗漏了什么吗?
[edit] dfsq 指出它应该是 bs-on-select
,关于图书馆的来源。我刚刚尝试了这个变体,但是事件只被触发一次。我创建了 this Plunker 来说明我的问题; "Number of selection events" 自然应该随着每次选择而递增,但它仍然是 1.