onselect not calling function when a match is selected error Uncaught ReferenceError: myFunction is not defined
onselect not calling function when a match is selected error Uncaught ReferenceError: myFunction is not defined
我正在尝试使用 angular-strap 中的 bs-typeahead 指令。
* 更新 *
我想要在用户从选项中选择某些内容时执行一个功能。但是这个简单的案例似乎并没有在这里工作并抛出错误:
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 没有错误,但如果您希望在每次更改时调用该函数,请删除环绕括号:
bs-on-select="myFunction"
现在您正在就地调用它,并将函数的 return 值(什么都没有)分配为 bs-on-select
处理程序。
我正在尝试使用 angular-strap 中的 bs-typeahead 指令。
* 更新 *
我想要在用户从选项中选择某些内容时执行一个功能。但是这个简单的案例似乎并没有在这里工作并抛出错误:
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 没有错误,但如果您希望在每次更改时调用该函数,请删除环绕括号:
bs-on-select="myFunction"
现在您正在就地调用它,并将函数的 return 值(什么都没有)分配为 bs-on-select
处理程序。