Last active
July 24, 2017 11:25
-
-
Save powellmichael/1cf9626888c48c403d0df0389793957f to your computer and use it in GitHub Desktop.
NG Character count directive
This file contains 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
https://stackoverflow.com/questions/20603107/angularjs-text-area-character-counter | |
.directive('charCount', ['$log', '$timeout', function($log, $timeout){ | |
return { | |
restrict: 'A', | |
compile: function compile() | |
{ | |
return { | |
post: function postLink(scope, iElement, iAttrs) | |
{ | |
iElement.bind('keydown', function() | |
{ | |
scope.$apply(function() | |
{ | |
scope.numberOfCharacters = iElement.val().length; | |
}); | |
}); | |
iElement.bind('paste', function() | |
{ | |
$timeout(function () | |
{ | |
scope.$apply(function() | |
{ | |
scope.numberOfCharacters = iElement.val().length; | |
}); | |
}, 200); | |
}); | |
} | |
} | |
} | |
} | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment