(function (angular, app) { app.directive("ngUniqe", function () { return { restrict: "A", require: "ngModel", link: function ($scope, $element, $attr, ngModel) { let options = $scope.$eval($attr.ngUniqe); ngModel.$validators.uniqe = function (modelValue) { let idx = options.items.findIdx(options.property, modelValue); return (idx === -1 || idx === options.index); }; } }; }); })(window.angular, app);