I am trying to build a 'show more' button for my app and I have encountered an issue.
I have a directive to do stuff when user click read more button
(function(window, angular) {
var app = angular.module('myApp');
app.directive('readMore', [
function() {
return {
restrict: 'A',
template:'<a class="read-more-button"></a>',
link: function(scope, element) {
element.bind('click', function(){
// do stuff
})
}
};
}
]);
})(window, angular);
Html
<div id="container">
<div ng-repeat="item in items">
{{item.description}}
</div>
</div>
<a ng-show="items.length > 10" read-more href="#"></a>
//only show read more button when I have more than 10 items
CSS:
#container {
height: 250px;
overflow: hidden;
}
The problem is sometimes a single item.description
has long texts and my #container
div can only hold 8 items and the rests are hidden. I don't want to count the letters because I thought that's not practical. Is there anyway to fix this? Thanks for the help!
Update:
The desired result will be: When click read more button, the div size will expand to whatever it should be. Currently the read more button will show only if the app has > 10 items. My question is how to show/hide read more button properly when 8 items texts already fill 250px div but I actually have 9 items (so it should show read more button but since it only has 9 items, the read more button won't show.)
The bottom line is: I need to know when to show read more button when the #container div is filled with texts regardless how many items I have