I am trying to use bs-typeahead directive from angular-strap.
I want a fucntion to be executed when a user selects something from the options. But this simple case is not seems to be working here and throwing error:
Uncaught ReferenceError: myFunction is not defined
Here is my syntax:
<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>
$scope.myFunction = function(){
console.log("This function is called.")
console.log($scope.selectedState);
}
Can anyone please help me here, if I am missing anything.
Here is my plunker: http://plnkr.co/edit/Z89TQ027WzxQn6UDJfAL?p=preview
答案 0 :(得分:0)
您链接的Plunker没有错误,但如果您希望在每次更改时调用该函数,请删除包装括号:
bs-on-select="myFunction"
现在你正在调用它,并将函数的返回值(什么都不是)分配为bs-on-select
处理程序。