onselect not calling function when a match is selected error Uncaught ReferenceError: myFunction is not defined

时间:2017-06-19 14:04:24

标签: javascript angularjs angular-strap

I am trying to use bs-typeahead directive from angular-strap.

* Update *

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

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:

Template

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

Can anyone please help me here, if I am missing anything.

Here is my plunker: http://plnkr.co/edit/Z89TQ027WzxQn6UDJfAL?p=preview

1 个答案:

答案 0 :(得分:0)

您链接的Plunker没有错误,但如果您希望在每次更改时调用该函数,请删除包装括号:

bs-on-select="myFunction"

现在你正在调用它,并将函数的返回值(什么都不是)分配为bs-on-select处理程序。