2017-02-22 19 views
1

У меня есть поле почты с рисунком:угловой - образец и нг-модель ошибки

pattern="^(([^<>()\[\]\.,;:\[email protected]\']+(\.[^<>()\[\]\.,;:\[email protected]\']+)*)|(\'.+\'))@(([^<>()[\]\.,;:\[email protected]\']+\.)+[^<>()[\]\.,;:\[email protected]\']{2,})$" 

и директивы, которые используют ngModel на том же поле:

<input pattern="^(([^<>()\[\]\.,;:\[email protected]\']+(\.[^<>()\[\]\.,;:\[email protected]\']+)*)|(\'.+\'))@(([^<>()[\]\.,;:\[email protected]\']+\.)+[^<>()[\]\.,;:\[email protected]\']{2,})$" 
         dir= "ltr" 
         class="form-control sgn-rounded_textbox" 
         name="emailBox1" 
         type="email" 
         ng-model="vm.model.emails.emailField" 
         input-change = vm.mail> 

директива inputChange:

(function() { 
     function inputChange($log, $timeout, $q, appCmdService) { 

      return { 
       restrict: 'A', 
       require: 'ngModel', 
       scope: { 
        inputChange: '=' 
       }, 
       link: function (scope, element, attrs, ngModel) { 
        var el = element[0]; 

        if (checkForENSettings(scope)) { 

         if (ngModel) { // Don't do anything unless we have a model 
          ngModel.$parsers.push(function (value) { 
           if(value){ 
            //some logic to change the value.... 
            ngModel.$setViewValue(value); 
            // renders the input with the new viewValue 
            ngModel.$render(); 
            //set cusor position 
            el.setSelectionRange(start, end); 
            //$log.log('ngModel.$parsers newVal', value); 
            return value; 
           } 
          }); 
          ngModel.$formatters.push(function (value) { 

           ngModel.$setViewValue(value); 
           // renders the input with the new viewValue 
           ngModel.$render(); 

           return value; 
          }); 
         } 

        } 

        function checkForENSettings(scope){ 
         if(scope.inputChange && scope.inputChange.lang === 'en'){ 
          return true; 
         } 
        } 

       } 
      };  
} 
     angular.module('common').directive('inputChange', inputChange); 

    })(); 

input-change работает на любом поле без поля pattern, но когда com baining их я получаю

Cannot assign to read only property 'message' of object '[object DOMException]' 

Follwed по

Error: [$rootScope:inprog] $digest already in progress 

Есть ли способ использовать ngModel и pattern на том же input поле?

Спасибо.

ответ

1

Оказывается, что существует проблема с HTML5 input type="email" и получения элемента selectionStart или selectionEnd известный вопрос о - HTML5 input email ans selection.

Устранено путем удаления type="email".