Created
April 6, 2016 07:37
-
-
Save hsleonis/096a5c9b0f9236f8d51c6c6d1edec28f to your computer and use it in GitHub Desktop.
Filters on ng-model in an input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // <input ng-model="sth" ng-trim="false" custom-validation> | |
| 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; | |
| }); | |
| } | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment