在 AngularJs 中的 ng-submit 中使用三元运算符

Rah*_*war -1 javascript angularjs

<form ng-if="userCtrl.show"
    ng-submit="userCtrl.showOtpForm : userCtrl.verifyOtp() ? userCtrl.sendOtpToEmail()" >......</form>
Run Code Online (Sandbox Code Playgroud)

我想在 中使用三元运算符ng-submit。就像当 show 变量的userController计算结果为 true 时,verifyOtp()应该调用函数,否则调用另一个函数。但我一直收到语法错误。

Lia*_*eth 5

你的三元看起来不正确,试试这个:

 ng-submit="userCtrl.showOtpForm ? userCtrl.verifyOtp() : userCtrl.sendOtpToEmail()" 
Run Code Online (Sandbox Code Playgroud)