Reputation: 34
I used ng-repeat to generate some html elements . like this:
<textarea ng-repeat="t in tips">{{t.content}}</textarea>
then i want to resize all of textarea's hight according to t.content. and textarea width is fixed ,what should i do?
Upvotes: 0
Views: 28
Reputation: 193261
You should write a directive for this. Maybe similar to this basic one:
app.directive('adjustHeight', function($timeout) {
return {
link: function(scope, element) {
$timeout(function() {
element[0].style.height = element[0].scrollHeight + 'px';
});
}
};
});
and use it like this:
<textarea ng-repeat="t in tips" adjust-height>{{t.content}}</textarea>
It's very naive of course, but you can get the idea. Of course you can build something more sophisticated on top of it if you need for example dynamic resize.
Upvotes: 1