app.directive('customValidation', function(){
return {
require: 'ngModel',
link: function(scope, element, attrs, modelCtrl) {
modelCtrl.$parsers.push(function (inputValue) {
var transformedInput = inputValue.toLowerCase().replace(/ /g, '');
if (transformedInput!=inputValue) {
modelCtrl.$setViewValue(transformedInput);
modelCtrl.$render();
}
return transformedInput;
});
}
};
});
<input ng-model="sth" ng-trim="false" custom-validation>
$scope.$watch('tags ',function(){
$scope.tags = $filter('lowercase')($scope.tags);
});
https://stackoverflow.com/questions/14419651/filters-on-ng-model-in-an-input