javascript - 使用 ng-click Angularjs 调用多个方法

标签 javascript angularjs ionic-framework

在 ng-click 控件中调用两个方法的语法是怎样的。

HTML

ng-click="submitForm(M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13, M14, M15), postComments(comment)">

我试过带逗号和不带逗号。

错误

Error: [$parse:syntax] Syntax Error: Token ',' is an unexpected token at column 77 of the expression [submitForm(M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13, M14, M15), postComments(comment)] starting at [, postComments(comment)].
http://errors.angularjs.org/1.4.3/$parse/syntax?p0=%2C&p1=is%20an%20unexpected%20token&p2=77&p3=submitForm(M1%2C%20M2%2C%20M3%2C%20M4%2C%20M5%2C%20M6%2C%20M7%2C%20M8%2C%20M9%2C%20M10%2C%20M11%2C%20M12%2C%20M13%2C%20M14%2C%20M15)%2C%20postComments(comment)&p4=%2C%20postComments(comment)
    at REGEX_STRING_REGEXP (http://localhost:8100/lib/ionic/js/ionic.bundle.js:8895:12)
    at Object.AST.throwError (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21708:11)
    at Object.AST.ast (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21478:12)
    at Object.ASTCompiler.compile (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21927:31)
    at Parser.parse (http://localhost:8100/lib/ionic/js/ionic.bundle.js:22776:29)
    at $parse (http://localhost:8100/lib/ionic/js/ionic.bundle.js:22900:39)
    at http://localhost:8100/lib/ionic/js/ionic.bundle.js:57510:7
    at IonicModule.config.factory.directive.directive.restrict (http://localhost:8100/lib/ionic/js/ionic.bundle.js:57526:5)
    at invokeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17477:9)
    at nodeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:16977:11) <ion-item class="item-balanced item item-complex" href="#/app/checklist" value="submit" ng-click="submitForm(M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13, M14, M15), postComments(comment)">

最佳答案

您需要在函数调用之间放置一个;(分号),而不是,(逗号)

ng-click="submitForm(M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13, M14, M15); postComments(comment)">

关于javascript - 使用 ng-click Angularjs 调用多个方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32371283/

相关文章:

javascript - “app-element”不是已知的 Angular 元素

javascript amCharts 图形项点击事件

javascript - 如何将输出简化为每个副本只有一个值

javascript - ng-class 绑定(bind)到子作用域中的不同变量而不是分配的变量

php - HTTP Post 方法不适用于 AngularJS + PHP + MySQL

Angularjs 嵌套状态 : 3 level

javascript - ionic angular 对于 ng-bind 和 {{}} 的工作方式不同不知道为什么?

javascript - 了解 yield 如何影响 JS 生成器中的返回值

javascript - 如何使用 angularjs 在 html 中插入 QlikSense 元素

angularjs - 使用 org.apache.cordova.file 获取选定的文件大小