I have a repeat with a bunch of text I want to apply the ellipsis to. I am using jquery dotdotdot. dotdotdot documentation
I made a simple directive that looks like
angular.module('core').directive('dotdotdot', [function () {
return {
required: 'ngBind',
restrict: 'A',
replace: false,
priority: 100,
link: function ($scope, element, attrs, ctrl) {
$scope.isTruncated = false;
$scope.hasRun = false;
$scope.$watch(element.html(), function (value) {
if (!$scope.hasRun) {
$scope.hasRun = true;
element.dotdotdot({watch:'window',
after: 'a.dotdotdotMore'});
$scope.isTruncated = element.triggerHandler('isTruncated');
if ($scope.isTruncated){
console.log('Truncated');
} else {
console.log('NOT Truncated');
}
}
});
}
};
}]);
It works fine applying the ellipsis but when someone clicks the item I want it to expand.
My html looks like
<div class="review item" data-ng-repeat="review in creator.reviews | orderBy:'order' track by $index">
<h1 dotdotdot data-ng-bind="review.review" class="testimonial" data-ng-class="{'testimonial-truncate': showTestimonial !== $index}" data-ng-click="testimonialClick($index);"></h1>
</div>
the css for testimonial-truncate is
.testimonial-truncate {
max-height:200px;
}
my click function looks like
$scope.testimonialClick = function (index) {
if ($scope.showTestimonial && $scope.showTestimonial === index) {
$scope.showTestimonial = -1;
} else {
$scope.showTestimonial = index;
}
$timeout(function() {
$('.testimonial').trigger('update');
}, 200);
};
It seems like the code is all being called but the text is still truncated to the maximum height even though that class is removed.
I am looking for a solution so either how do I get what I have done working or is there a better way to do this.