2015-02-06 146 views
0

我正在尝试使用AngularJS提交表单而不使用$ http。我通过Javascript检查表单,但不知道如何在检查完成后提交。示例代码如下所示:AngularJS提交表单提交

AngularJS

app.directive('checkLoggedinSubmit', ['account_id', 'session', 'LoginModal', 
    function(account_id, session, LoginModal) { 
     return { 
      restrict : 'A', 
      link : function(scope, element, attrs) { 

       element.bind('submit', function(e) { 
        e.preventDefault();    

        //If not logged in, show logged in, otherwise subit 
        if (!account_id && !session.read('account_id')) { 
         LoginModal.show(); 
        } else { 
         scope.$eval(attrs.checkLoggedinSubmit); 
         scope.$apply(); 
         //Tried To use JQuery 
         //$(e.currentTarget).submit(); 
        } 

       }); 

      } 
     }; 

}]); 

HTML表单

<form role="form" enctype="multipart/form-data" method="post" action="/file/submit" class="well" style="padding: 0px 20px 20px;" check-loggedin-submit > 
    <div class="form-group"> 
     <input type="file" name="my_file" /> 
    </div> 

    <div class="form-group"> 
     <input type="submit" class="btn btn-success" /> 
    </div> 

</form> 

我想有JQuery的提交表单,但扔了错误。任何人现在如何解决这个问题?

+0

我认为最简单的方法是将'e.preventDefault();'调用移到你的'if'语句中,所以它只会在需要的时候被调用。 – 2015-02-06 05:09:57

回答

0

尝试:

<input type="submit" data-ng-click="save(input) class="btn btn-success" /> 

保存是JQuery的方法名和输入PARAMS。