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
angularjs directive


source to share


No one has answered this question yet

Check out similar questions:

4523
Thinking in AngularJS if I have a jQuery background?
3178
AngularJS: Service vs provider vs factory
1690
How does data binding work in AngularJS?
1195
How do I access the $ scope variable in the browser console using AngularJS?
1073
How to use $ scope. $ Watch and $ scope. $ Apply in AngularJS?
998
What is the difference between "@" and "=" in scope in AngularJS?
912
'this' vs $ scope in AngularJS controllers
415
AngularJS 1.2 $ injector: modulerr
12
Set invalid input if typeahead-editable is false
1
What is scope. $ ModelValue in AngularJS?



All Articles
Loading...
X
Show
Funny
Dev
Pics