Html 用于选择的 Angular ng-change 不调用声明的方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17005120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:15:16  来源:igfitidea点击:

Angular ng-change for select not calling the declared method

javascripthtmlselectangularjs

提问by user6123723

I have the following html form select statement

我有以下 html 表单选择语句

<select ng-change="setBillGroup()" ng-model="bill.groupId" class="span8" ng-options="d.id as d.name for d in groups"></select>

and the js

和 js

myApp.controller('myAppController', function($scope, myAppService) {

.....
function setBillGroup(){
 console.log("setBillGroup method called!");
    ......
 }

....
});

But for some reason the setBillGroup() never seems to get called when I select something or the other in the form.

但是由于某种原因,当我在表单中选择某些内容时,似乎永远不会调用 setBillGroup()。

回答by Ufuk Hac?o?ullar?

You have to define the method in the scope.

您必须在范围内定义方法。

$scope.setBillGroup = function(){
 console.log("setBillGroup method called!");
    ......
 };