Convert AngularJS 1.2 Compliance Checker to 1.3

The below validation directive works well. Can anyone help me convert this to angularjs 1.3 $ syntax syntax. Any help as soon as possible would be greatly appreciated.

(function () {
'use strict';
angular.module('myApp').directive('validFees', function () {
    return {
        restrict: 'A',
        require: 'ngModel',
        scope: {
            studentCategory: '='
        },
        link: function (scope, element, attrs, ngModel) {
            scope.$watch(function () {
                var modelValue = ngModel.$modelValue || ngModel.$$invalidModelValue;
                var studentCategory = scope.studentCategory;

                if (studentCategory === 'HandiCaped') {
                    return modelValue !== 'FeesShouldBePaid';
                } else {
                    return true;
                }
            }, function (validity) {
                ngModel.$setValidity('validFees', validity);
            });
        }
    };
});

      

} ());

Edit: (I have to make it simpler. Ignore the above code. Please help convert the below code to 1.30 syntax using $ validators)

angular.module('myApp').directive('greaterThanFive', function () {
return {
    restrict: 'A',
    require: 'ngModel',
    link: function (scope, element, attrs, ngModel) {
        scope.$watch(function () {
            var modelValue = ngModel.$modelValue || ngModel.$$invalidModelValue;

            return modelValue > 5;

        }, function (validity) {
            ngModel.$setValidity('greaterThanFive', validity);
        });
    }
};

      

});

+3


source to share





All Articles