Answer the question
In order to leave comments, you need to log in
How to dynamically change textarea height in AngularJS directive?
All the best.
Please tell me how to dynamically change the height of a textarea using AngularJS depending on the content.
I made this directive:
.directive('textareaHeight', [
function () {
return {
restrict: 'A',
require: 'ngModel',
link: function postLink(scope, element, attrs, ngModel) {
element.bind('input propertychange', function () {
if (angular.element(element[0]).height() < element[0].scrollHeight) {
angular.element(element[0]).css('height', element[0].scrollHeight + 2).css('transition', 'height 200ms ease')
}
});
}
};
}]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question