用ng-click Angularjs调用多个方法

Calling multiple methods with ng-click Angularjs

本文关键字:方法 调用 ng-click Angularjs      更新时间:2023-09-26

在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)">