if statement in ng-click

后端 未结 8 1026
鱼传尺愫
鱼传尺愫 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:11

    Don't put any Condition Expression in Template.

    Do it at the Controller.

    Template:

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

    Controller:

    $scope.check = function(value) {
        if (value) {
           updateMyProfile();
        }
    }
    
    0 讨论(0)
  • 2020-12-08 02:17

    Write as

    <input type="submit" ng-click="profileForm.$valid==true?updateMyProfile():''" name="submit" value="Save" class="submit" id="submit">
    
    0 讨论(0)
提交回复
热议问题