Skip to content

Instantly share code, notes, and snippets.

@leminh111
Forked from enapupe/autogrow.js
Created February 1, 2018 00:52
Show Gist options
  • Save leminh111/1dcd9e85d30601fda814978a9ce49c98 to your computer and use it in GitHub Desktop.
Save leminh111/1dcd9e85d30601fda814978a9ce49c98 to your computer and use it in GitHub Desktop.
Auto Grow/Shrink textarea directive for AngularJS (credits to this gist https://gist.github.com/thomseddon/4703968, specially @huyttq)
angular.module("myApp").directive("autoGrow", function(){
return function(scope, element, attr){
var update = function(){
element.css("height", "auto");
var height = element[0].scrollHeight;
if(height > 0){
element.css("height", height + "px");
}
};
scope.$watch(attr.ngModel, function(){
update();
});
attr.$set("ngTrim", "false");
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment