自訂驗證規則

html
====
<input validator1 type='text' class='form-control' ng-model='uniform'><span style='color:red' ng-show="form1.$error.validator1">*</span>

javascript
====
directive("validator1", function () {
        return {
            restrict: 'A',
            require: "ngModel",
            link: function (scope, element, attributes, ngModel) {
                ngModel.$validators.validator1 = function (modelValue, viewValue) {
                    ... // return true or false
                }
            }
        };
    })

留言

熱門文章