-
-
Save cod3cow/3a4c1b532e4e041a5c2f to your computer and use it in GitHub Desktop.
simple autogrow directive for textareas in angularjs
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
// Usage: <textarea auto-grow></textarea> | |
appModule.directive('autoGrow', function() { | |
return function(scope, element, attr){ | |
var update = function(){ | |
element.css("height", "auto"); | |
element.css("height", element[0].scrollHeight + "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