2017-06-09 7 views
0

thymeleafの使用時にカスタムディレクティブを書くにはどうすればよいですか?オフトピックthymeleafを使用したカスタムディレクティブ

:たとえば、私はあなたのinputタグにrequiredを使用する場合はth:required="required"

私はこのエラーが発生したので、私はカスタムディレクティブのためにそれをどのように行うことができますし、それを変更する必要があることを見た:

org.xml.sax.SAXParseException: Open quote is expected for attribute "is-email" associated with an element type "input".

私はこのタグを使用する場合:

<input type="email" id="clientEmail" name="clientEmail" class="form-control" ng-model="c.email" th:required="required" minlength="5" 
      is-email={{c.email}} /> 

カスタムディレクティブ:

<input type="email" id="clientEmail" name="clientEmail" class="form-control" ng-model="c.email" th:required="required" minlength="5" 
      is-email="{{c.email}}" /> 

から

angular.module('app') 
.directive('isEmail', function() { 
    return { 
    restrict: 'A', 
    require: 'ngModel', 
    link: function(scope, element, attributes, ctrl) { 
     ctrl.$validators.isEmail = function(modelValue, viewValue) { 
     if (viewValue) { 
      var re = /^(([^<>()\[\]\\.,;:\[email protected]"]+(\.[^<>()\[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 
      return re.test(viewValue); 
     } 
     } 
    } 
    } 
}) 

答えて

1
<input type="email" id="clientEmail" name="clientEmail" class="form-control" ng-model="c.email" th:required="required" minlength="5" 
      is-email={{c.email}} /> 

変更これは、あなただけの"{{c.email}}"引用符

を言及するのを忘れてしまいました
関連する問題