Javascript 如何在angularJS中调用ng-change的多个函数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39698510/
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-23 22:49:10  来源:igfitidea点击:

How to call multiple functions on ng-change in angularJS?

javascriptangularjs

提问by Suhas V

ng-change = "ControllerName.functionName()"

ng-change = "ControllerName.functionName()"

here I want to add one more function to that. How can I do that ?

在这里,我想再添加一个功能。我怎样才能做到这一点 ?

Thanks in advance.

提前致谢。

回答by Stefan Rein

This should do the trick:

这应该可以解决问题:

ng-change = "ControllerName.functionName(); ControllerName.anotherFunction();"

回答by frikkievb

Why not rather group the functions in the controller inside another function?

为什么不将控制器中的功能分组到另一个功能中?

function onChangeGroup(){
 doStuff();
 doMoreStuff();
}

<input ng-change="ControllerName.onChangeGroup()"/>

Regards

问候

回答by pawan sen

This is working properly but one controller in both function.

这工作正常,但两个功能中的一个控制器。

ng-change = "function1();function2();"

回答by Ferdous Wahid

for angular version 1.* : ng-change = "function1();function2();"

对于角度版本 1.* : ng-change = "function1();function2();"

for angular version 2.* or more: (change)= "function1();function2();"

对于 Angular 版本 2.* 或更高版本: (change)= "function1();function2();"

回答by Ayaz Shah

You just need to add another function in the same double quotes.

您只需要在相同的双引号中添加另一个函数。

ng-change = "ControllerName.functionFirst(); ControllerName.functionSecond();"

You can use ng-changefor multi expression by adding semicolon ;after each expression

您可以ng-change通过;在每个表达式后添加分号来用于多表达式