表单的服务器端验证

表单的默认验证我按预期工作。但是,当用户键入有效的电子邮件地址和最少三个字符的密码时,这并不意味着登录凭据有效。

The default validation for the form I have works as expected. But when a user types in a valid email address and a password of three characters minimum, that doesn't mean the login credentials are valid.

所以我的问题是:


如何在$ b $之后将模型电子邮件密码设置为无效b 服务器端验证,因此输入字段获取类ng-invalid而非ng-valid。

How can I set the model email and password to invalid after server-side validation, so the input-fields get the class ng-invalid instead of ng-valid.

我当前的代码

function IndexCtrl( $scope, $http )
{
  $scope.form = {};
  $scope.submitLogin = function ()
  {
    $http.post( '/api/auth/login', $scope.form ).success( function( data )
    {
      if ( !data.success )
      {
        $scope.form.errors = [ data ];

        // here I also want to mark the models 'email' and 'password' as invalid, so they both get the class 'ng-invalid'
      }
      else
      {
        $location.path( '/' );
      }
    });
  };
}




 1 条回答