问题
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