I have implemented a directive that allows me to input editable content inside a tag
Recently, I made modifications to include a character counter feature.
However, I noticed that when I add line breaks, the character count increases erroneously.
https://i.sstatic.net/Ry4aS.jpg
In the image shown, the counter indicates 4 characters although visually there are only two.
https://i.sstatic.net/FsGgV.jpg
In this scenario, the "<" symbol is being counted as 4 characters instead of just one, and not accounting for ">".
I am looking for an accurate way to calculate the number of characters entered.
Below is the directive code used:
directives.directive('contenteditable', ['$timeout', function($timeout) {
return {
restrict: 'A',
require: ['^?ngModel'],
link: function(scope, element, attrs, args) {
var ngModel = args[0];
if (ngModel === null) {
return null;
}
// Code logic goes here
// More code...
}
};
}]);