frSame.js 658 Bytes
/**
 * Directive that sets `same` validator on the model. This validator checks that
 * value of the model is the same as the value specified by the directives
 * attribute.
 */

angular.module('fr.same', [])

.directive('frSame', function () {
    return {
        require: 'ngModel',

        scope: {
            same: '=frSame',
        },

        link: function (scope, element, attributes, ngModel) {
            ngModel.$validators.same = function (modelValue) {
                return modelValue == scope.same;
            };

            scope.$watch('same', function () {
                ngModel.$validate();
            });
        },
    };
});