2

私は私の正規表現パターン

(^([Aa][Ss])[0-9]{8})|(^6[0-9]{7}) 

としてこれを持っている私は、以下のコンソールエラーが発生しますが、それは動作します!:

libraries-c8d65edf41.js:22505 Error: [$parse:lexerr] Lexer Error: Unexpected next character at columns 1-1 [^] in expression [(^([Aa][Ss])[0-9]{8})|(^6[0-9]{7})]. 

http://errors.angularjs.org/1.5.2/ $パース/ lexerr?P0 =予期%の20nextharacter%20の& P1 = S%201から1パーセント20%5B%5E%5D & P2 =(%の5E(%の5BAaの%の5Dの%5BSs%の5D)%5B0-9%の5D %7B8%の7D)%7C(%の5E6の%5B0-9%の5D%7B7%の7D)

任意のアイデアコンソールエラーを取り除く方法について教えてください。おかげさまで ここ

はディレクティブHTML

<div class="input"> 
<div data-ng-class="{'input-group': label}"> 
    <div class="input-group-addon" 
     data-ng-if="label"> 
     {{label}} 
     <span class="required" 
      data-ng-if="required && isEditable"> 
      * 
     </span> 
    </div> 
    <div class="input-group-addon required" 
     data-ng-if="!label && required && isEditable"> 
     * 
    </div> 
    <div class="form-control" 
     title="{{object[key] || 'N/A'}}" 
     data-ng-if="!isEditable"> 
     <span>{{object[key] || 'N/A'}}</span> 
    </div> 
    <div class="form-control editable" 
     title="{{object[key] || 'N/A'}}" 
     data-ng-if="isEditable && !isEditing" 
     data-ng-click="edit()"> 
     <span> 
      <a href="">{{object[key] || 'N/A'}}</a> 
     </span> 
    </div> 
    <input class="form-control" 
     data-ng-if="isEditable && isEditing" 
     data-ng-model="model.value" 
     data-ng-keydown="onKeypress($event)" 
     data-ng-blur="save()" 
     data-ng-pattern="regexPattern" 
     name="{{inputName}}" 
     data-csdp-autofocus /> 
</div> 

、ここでは、指令

(function (angular) { 
'use strict'; 

angular.module('commons.directives.forms') 
    .directive('exInput', InputDirective); 

InputDirective.$inject = ['$q', 'commons.constants.KeyCodeConstant']; 

function InputDirective ($q, KeyCodeConstant) { 
    return { 
     restrict: 'A', 
     replace: true, 
     templateUrl: 'commons/directives/forms/input.directive.html', 
     link: link, 
     scope: { 
      input: '@exInput', 
      isEditable: '=?', 
      object: '=ngModelObject', 
      key: '@ngModelKey', 
      autofocus: '=?', 
      required: '@ngRequired', 
      inputName: '@inputName', 
      regexPattern: '@ngPattern', 
      preEditing: '&', 
      onEditing: '&', 
      onSave: '&', 
      onCancel: '&', 
      onFinally: '&', 
      onInit: '&' 
     } 
    }; 

    function link (scope) { 
     scope.edit = edit; 
     scope.save = save; 
     scope.cancel = cancel; 
     scope.onKeypress = onKeypress; 
     scope.label = scope.input; 
     scope.model = { value: '' }; 
     scope.isEditing = scope.autofocus ? scope.autofocus : false; 

     var oldValue; 

     function edit() { 
      $q.when(scope.preEditing()).then(function() { 
       oldValue = scope.object[scope.key]; 
       scope.model.value = oldValue; 
       scope.label = '> ' + scope.input; 
       scope.onEditing(); 
       scope.isEditing = true; 
      }); 
     } 

     function save() { 
      scope.object[scope.key] = scope.model.value; 
      scope.onSave(); 
      onFinally(); 
     } 

     function cancel() { 
      scope.object[scope.key] = oldValue; 
      scope.onCancel(); 
      onFinally(); 
     } 

     function onKeypress (event) { 
      if (event.keyCode === KeyCodeConstant.ENTER) { 
       save(); 
      } else if (event.keyCode === KeyCodeConstant.ESC) { 
       cancel(); 
      } 
     } 

     function onFinally() { 
      scope.label = scope.input; 
      scope.isEditing = false; 
      scope.onFinally(); 
     } 

     scope.onInit({ $scope: scope }); 
    } 
} 

})のためのJS)が(角度です。

ここではどのように使用していますか。その属性ng-patternから正しくregxを読むためにパーサを助けるので、regx式の開始&末尾に文字0​​をエスケープ

<input class="form-margin" 
         data-ex-input="Assignment ID" 
         data-is-editable="true" 
         data-ng-model-object="vm.contract" 
         data-ng-pattern="{{vm.AssignmentIdRegex}}" 
         data-input-name="assignmentId" 
         data-ng-model-key="assignmentId" /> 
        <div class="alert alert-info" 
        data-ng-show="contractForm.assignmentId.$error.pattern && contractForm.assignmentId.$dirty"> 
         <strong>Assignment ID: </strong>ie. AS12345678 or 61234567 
        </div> 

答えて

4

使用。

ng-pattern="/(^([Aa][Ss])[0-9]{8})|(^6[0-9]{7})/" 

を入力渡さ:As00000000 & 61234567

Demo Plunkr

+0

は私がすることを試みたが、それは私のために仕事をdidntの。問題は私の指示に由来する可能性が最も高いです。私は入力ディレクティブを作成し、今ではディレクティブに正規表現を渡しています。 –

+0

あなたはplunkrをチェックしましたか? –

+0

私は完全な問題を追加しました。私はそれがディレクティブ自体から、正規表現を渡す方法について、私は前後に2つを追加しないとうまくいくと思いますが、コンソールにエラーメッセージが表示されます。私は2つの/ –

関連する問題