2017-06-19 41 views
0

我想从角度带使用bs-typeahead指令。选择匹配时onselect不调用函数错误未捕获ReferenceError:myFunction未定义

*更新*

http://mgcrea.github.io/angular-strap/#/typeaheads

我希望当用户选择从选项的东西要执行的温控功能。但这种简单的情况下,不似乎是在这里工作和投掷的错误:

Uncaught ReferenceError: myFunction is not defined

这里是我的语法:

模板

<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); 
} 

任何人都可以如果我缺少任何东西,请在这里帮助我。

这里是我的plunker:http://plnkr.co/edit/Z89TQ027WzxQn6UDJfAL?p=preview

回答

0

您联系Plunker没有错误,但如果你想被叫做每一个变化的功能,去掉包装括号:现在你

bs-on-select="myFunction" 

”重新调用它,并将该函数的返回值(这是什么)指定为bs-on-select处理函数。

相关问题