View on GitHub

Angular Ellipsis

Angular directive to truncate multi-line text to visible height

Below are examples of the Angular Ellipsis Directive in action. The directive is fully responsive; it will update on window resizing. All that is required is for the element to have a set height or max-height. Custom append text (which are wrapped in a span tag) is shown in bold and red. These styles are set to highlight functionality, and are by default not styled. All of the examples below use max-height unless specifically noted.

Angular Ellipsis Examples

Basic Usage
<p data-ng-bind="paragraphText" data-ellipsis></p>

Custom Ellipsis Symbol/String
<p data-ng-bind="paragraphText" data-ellipsis data-ellipsis-symbol="--"></p>

Custom Append Text
<p data-ng-bind="paragraphText" data-ellipsis data-ellipsis-append="read more"></p>

Custom Ellipsis Symbol/String and Append Text
<p data-ng-bind="paragraphText" data-ellipsis data-ellipsis-symbol="---" data-ellipsis-append="read more"></p>

Custom Append Text using Scope Variable
<p data-ng-bind="paragraphText" data-ellipsis data-ellipsis-append="{{ellipsisText}}"></p>

Custom Append Text using Updating Scope Variable
<p data-ng-bind="paragraphText" data-ellipsis data-ellipsis-append="{{incrementing}}"></p>

Custom Append Text with Click Function
<p data-ng-bind="paragraphText" data-ellipsis data-ellipsis-append="read more" data-ellipsis-append-click="showFullText()" ></p>

app.controller("EllipsisController", function($scope, $interval) {
  var i = 0;

  $scope.paragraphText = "Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate, we can not consecrate, we can not hallow, this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced.";

  $scope.ellipsisText = "But wait, there's more";

  $interval(function() {
    $scope.incrementing = "But wait, there's more x" + i;
  }, 1000);

  $scope.showFullText = function() {
    alert('On click function');