0
我試圖顯示消息時,密碼不匹配,但不是不顯示任何想法?我試圖顯示消息時密碼不匹配,但不是不顯示任何想法?Angularjs:顯示消息
指令:
angular.module('crud')
.directive('equal', function() {
return {
require: 'ngModel',
scope: {
equal: '='
},
link: function(scope, elem, attrs, ctrl) {
ctrl.$validators.equal = function(modelValue, viewValue) {
return modelValue === scope.equal;
};
scope.$watch('equal', function(newVal, oldVal) {
ctrl.$validate();
});
}
};
});
HTML
<form name="userForm" ng-submit="signup()" class="form-horizontal" role="form" >
<input type="password" class="form-control ng-invalid submitted" id="password" name="password" ng-model="password" ng-minlength="8" ng-maxlength="20" required />
<input type="password" equal="password" class="form-control ng-invalid submitted" id="confirmPassword" name="confirmPassword" ng-model="confirmPassword" required />
<span ng-show="userForm.password.$error.equal && userForm.password.$dirty">Passwords don't match.</span>
</form>
ü可以用NG的消息放好嗎? – nevergiveup
@nevergiveup當然,我更新了上面的代碼片段,以便它使用ng-messages – sielakos
當邊界不正確並且邊界格林函數相關時,如何將邊界置於紅色? – nevergiveup