angular ngMessages custom validation ng-message

扶醉桌前 提交于 2019-12-11 18:09:36

问题


I've got this custom validation

function uiEmailEquals() {
  return {
    require: 'ngModel',
    link: function(scope, element, attrs, ngModel) {
      scope.$watch(attrs.uiEmailEquals, function() {
        ngModel.$validate();
      });
      ngModel.$validators.isEquals = function(value) {
        var email = scope.$eval(attrs.uiEmailEquals);
        if (!email || !value) {
          return false;
        }
        return (value === email);
      };
    }
  };
}

<input type="email" tabindex="4" name="cemail" class="form-control" ng-model="vm.data.cemail" placeholder="confirm email" ng-required="true" ui-email-equals="vm.data.email"
/>
<div class="help-block" ng-messages="form.cemail.$error" ng-if="form.cemail.$touched">
    <p class="error-message" ng-message="required">Required</p>
    <p class="error-message" ng-message="email">Not valid email</p>
    <p class="error-message" ng-message="uiemailequals">uiemailequals</p>
    <p class="error-message" ng-message="ui-email-equals">ui-email-equals</p>
    <p class="error-message" ng-message="uiEmailEquals">uiEmailEquals</p>
    <p class="error-message" ng-message="equals">equals</p>
</div>

The problem is I don't find the exp to set inside

ng-message

Can you help me, please ?


回答1:


ngModel.$validators.isEquals - this is the name of your custom validator -> isEquals

<p class="error-message" ng-message="isEquals">is equals</p>



回答2:


method name is isEquals use ng-message="isEquals"



来源:https://stackoverflow.com/questions/39015743/angular-ngmessages-custom-validation-ng-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!