简体   繁体   English

Angular js Ng模式不允许更新模型

[英]Angular js Ng-pattern does not allow update the model

i have to validate the text box which shows the error message when user enters 4 digit as 9999.so i have used the ng-pattern method to show error message but ng-pattern does n't allow to update the object.my code is given below: 我必须验证当用户输入4位数字作为9999.时显示错误消息的文本框,因此我使用了ng-pattern方法显示错误消息,但是ng-pattern不允许更新对象。我的代码是如下:

  <md-input-container class="" style="margin:5px 0px; margin-right:15px;">

      <input type="password" name="numCode" ng-model="datas.part[1].Value" ng-value="datas.part[1].Value" maxlength="4" ng-pattern="/(?!9{4})\d{4}/" ng-keydown="vm.testCode(datas.part[1].Value)" class="ng-pristine ng-valid md-input ng-touched"  aria-invalid="false" style="" autocomplete="off" required>
      <div ng-messages="vm.formName.numCode.$error" class="allign-padding-bottom" role="alert">
           <div ng-message-exp="['minlength','maxlength','pattern']">
                        {{::'testcode'|translate}}
            </div>
       </div>
    </md-input-container>

 vm.testCode= function (val) {
            console.info("sdf",val);
            vm.showConfirmUserCode = true;
            ///vm.isDeviceEnabled = false;
        }

In ng-keydown method the model did n't update.it shows undefined in vm.formName.numCode.$viewvalue.kindly help me to sort out this problem & check my ng-pattern.if i remove my ng-pattern means i have the updated model 在ng-keydown方法中,模型没有更新。它在vm.formName.numCode。$ viewvalue.in中显示未定义,请帮助我解决此问题并检查ng-pattern.if我删除了ng-pattern意味着我有更新的模型

Please check this plunker: http://plnkr.co/edit/g0wsbFnfi6TEW76orxIJ?p=preview 请检查此插件: http ://plnkr.co/edit/g0wsbFnfi6TEW76orxIJ?p=preview

 <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>

    <form name="form1" novalidate>

  <input type="password" name="numCode" ng-model="inputText" ng-value="inputText" ng-pattern="/(?!9{4})\d{4}/" ng-maxlength="4" ng-keydown="testCode(inputText)" aria-invalid="false" style="" autocomplete="off" required>
  <div ng-messages="form1.numCode.$error" role="alert">
           <div ng-message="pattern">pattern error</div>
            <div ng-message="maxlength">maxlength error</div>
             <div ng-message="required">required error</div>
   </div>
</form>
  </body>

Have you referenced angular-messages as a seperate library? 您是否已将角度消息引用为单独的库? The ng-keydown works if its a valid text and the error messages are shown correctly. 如果ng-keydown的有效文本和错误消息正确显示,则可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM