我正在尝试使用来自角度带的bs-typeahead指令。
*更新*
http://mgcrea.github.io/angular-strap/#/typeaheads
我希望当用户从选项中选择某些内容时执行功能。但是这个简单的案例似乎在这里不起作用并抛出错误:
未捕获的引用错误:未定义 myFunction
这是我的语法:
模板
<input type="text" class="form-control" ng-model="selectedState" bs-options="state for state in states" bs-on-select="myFunction()" placeholder="Enter state" bs-typeahead>
.JS:
$scope.myFunction = function(){
console.log("This function is called.")
console.log($scope.selectedState);
}
如果我错过了什么,任何人都可以在这里帮助我。
这是我的褶皱:http://plnkr.co/edit/Z89TQ027WzxQn6UDJfAL?p=preview
您链接的 Plunker 没有错误,但如果您希望在每次更改时调用该函数,请删除包装括号:
bs-on-select="myFunction"
现在,您正在就地调用它,并将函数的返回值(什么都没有)分配为bs-on-select
处理程序。