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);
}
}
}
}
})