'use strict';
app.directive('unique', [function () {
    return {
      require: 'ngModel',
      restrict: 'A',
      scope: {
          unique: '='
      },
      link: function(scope, elem, attrs, ctrl) {
          scope.$watch(function() {
              var modelValue = ctrl.$modelValue || ctrl.$$invalidModelValue;
              return (ctrl.$pristine && angular.isUndefined(modelValue)) || scope.unique !== modelValue;
          }, function(currentValue) {
              ctrl.$setValidity('unique', currentValue);
          });
      }
    };
}]);
