the truth is strange what happens. I'm trying to limit a textarea that takes a description. use the "keypress" event in the browser and everything worked well, but the application is not working. No receipt errors or anything like that, just not working.
var limite = 140;
$scope.resta = 0;
$('#counter').html("Quedan "+limite+" caracteres");
$("#text_view").keyup(function(e, $event){
var box = $(this).val();
var value = (box.length *100) / limite;
$scope.resta = limite - box.length;
if(box.length <= limite || $scope.resta > 0){
$('#counter').html("Quedan "+$scope.resta+" caracteres");
}
else{
$('#counter').html("Quedan "+$scope.resta+" caracteres");
e.preventDefault();
return;
}
});
Also try keyup, this if it works, but in the textarea is still writing and not respesta the limit until the user presses a space.
Its not considered good practice to mix Angularjs and Jquery code together. If you don't have any option then move jquery code to directive. Angularjs is really powerful so you can do rellay amazing stuffs without jquery help with less amount of code. You can achieve your requirement without even a single code of jquery as below.
HTML
Javascript