Is there an ng-model and input type email bug?

后端 未结 4 1488
执笔经年
执笔经年 2021-02-07 05:58

Is there something special going on with input type=\"email\" and ng-model attribute? If the input is email, then the model doesnt update. If I change the input type to text, nu

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-07 06:26

    Starting from Angular 1.3, you can easily overwrite the 'email' validator and make it always return true.

    angular
      .module('myApp', [])
      .controller('MainController', function() {
        this.email = '';
      })
      .directive('noEmailValidation', function() {
        return {
          restrict: 'A',
          require: 'ngModel',
          link: function(scope, elm, attr, ctrl) {
            ctrl.$validators['email'] = function() {
              return true;
            };
          }
        }
      });
    
    
    Email: {{main.email}}

    Enjoy.

提交回复
热议问题