I want to implement a validation attribute with parameter. In particular attribute for validating maximum date in a custom format.
<input type="datetime" ng-model="someForm.someField" name="SomeField" max-date="2016.09.11" />
There are many examples of validating directives without parameters, so I've tried to base my code on them. I've added scope and restriction to attribute only usage of the directive.
fooApp.directive('maxDate', function () {
return {
restrict: 'A',
scope: {
max: '='
},
require: 'ngModel',
link: function ($scope, element, attrs, ngModel) {
ngModel.$validators.maxDate = function (value, max) {
//Here will be validator logic
};
}
}
});
The problem is - max is always the same as value. It's not value of max-date attribute, but the value of input field. What am I doing wrong?