I have the following directive
var notInModule = angular.module('ui.notIn', []);
notInModule.directive('notIn', function() { return { restrict: 'A', require: 'ngModel', link: function(scope, elm, attrs, ctrl) { var thisValue; var otherValues;
attrs.$observe('notIn', function(values) {
otherValues = values;
validate();
});
ctrl.$parsers.unshift(function(viewValue) {
thisValue = viewValue.toLowerCase();
validate();
return thisValue;
});
var validate = function() {
ctrl.$setValidity('isWithin', otherValues.some(function(value) {
return value.toLowerCase() === thisValue.toLowerCase();
}));
};
},
};
});
and i am using it like this
<input ng-model="sample.name" not-in={{sample}} required/>
sample is an array on scope. However , in the directive 's controller , it comes in as a string.
for eg :if $scope.sample = ["a","b"] ,
In the directive , values is got as "["a","b"]"