if statement in ng-click

后端 未结 8 1058
鱼传尺愫
鱼传尺愫 2020-12-08 01:42

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.

         


        
8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 02:07

    If you do have to do it this way, here's a few ways of doing it:

    Disabling the button with ng-disabled

    By far the easiest solution.

    
    

    Hiding the button (and showing something else) with ng-if

    Might be OK if you're showing/hiding some complex markup.

    Sorry! We need all form fields properly filled out to continue.

    (remember, there's no ng-else ...)

    A mix of both

    Communicating to the user where the button is (he won't look for it any longer), but explain why it can't be clicked.

    
    
    Sorry! We need all form fields properly filled out to continue.

提交回复
热议问题