I want to make height of textarea equal to height of the text within it (Even when the time of first-rendering resize and confirm with enter)...
The code from that page is below. I'd appreciate any help or pointers.
= = =
resizeTextarea.js
app.directive('resizeTextarea', function() {
return {
restrict: 'E',
transclude: true,
replace: true,
template: "<textarea placeholder='please fill in...'></textarea>",
link: function(scope, element, attrs) {
var HEIGHT = 25;
var el = angular.element(element[0])
el.css('lineHeight', HEIGHT + "px");
el.css('height', HEIGHT + "px");
var resize = function(e) {
var textHeight = e.target.scrollHeight;
var height = ~~(textHeight / HEIGHT) * HEIGHT
el.css('height', height + "px");
};
el.on('input', resize);
}
}
});
= = =
index.html
<div>
<resize-textarea></resize-textarea>
</div>