ng-click 中的 if 语句 [英] if statement in ng-click

查看:31
本文介绍了ng-click 中的 if 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 ng-click 中放置条件?在这里,我希望如果有任何表单错误,则不提交表单,但随后出现解析异常.

Is there a way to put a condition inside an ng-click? Here, I want that the form is not submitted if there are any form errors, but then I got a parse exception.

 <input  ng-click="{{if(profileForm.$valid) updateMyProfile()}}" name="submit" id="submit" value="Save" class="submit" type="submit">

我尝试使用 ng-disabled 但后来我的验证插件不起作用,因为根本没有提交表单,所以它没有被触发.

I tried to use ng-disabled but then my validation plugin does not work cause form is never submitted at all, so it is not triggered.

推荐答案

不要在模板中放置任何条件表达式.

在控制器处进行.

模板:

<input ng-click="check(profileForm.$valid)" name="submit" 
       id="submit" value="Save" class="submit" type="submit">

控制器:

$scope.check = function(value) {
    if (value) {
       updateMyProfile();
    }
}

这篇关于ng-click 中的 if 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆