ProductPromotion
Logo

Angular.JS

made by https://0x3d.site

GitHub - lentschi/ngx-ellipsis: Multiline text with ellipsis for angular 9+
Multiline text with ellipsis for angular 9+. Contribute to lentschi/ngx-ellipsis development by creating an account on GitHub.
Visit Site

GitHub - lentschi/ngx-ellipsis: Multiline text with ellipsis for angular 9+

GitHub - lentschi/ngx-ellipsis: Multiline text with ellipsis for angular 9+

ngx-ellipsis

Angular library providing a directive to display an ellipsis if the containing text would overflow.

Supports text only - No HTML contents! (If you really do need html contents to be truncated, you might want to take a look at my spin-off lib: ngx-nested-ellipsis. It is able to do just that, but takes slightly more processing power to perform its task.)

Demo

For a demo either just checkout this project and run npm install && npm run start or visit the StackBlitz demo page.

Installation

For use in an existing angular project run npm install ngx-ellipsis --save.

Usage

Add the directive to the component, in which you want to use the ellipsis:

import { EllipsisDirective } from 'ngx-ellipsis';

@Component({
  selector: 'your-fancy-component',
  // ...
  imports: [ 
    EllipsisDirective,
    // ...
  ],
  standalone: true
})
export class YourFancyComponent {}

Then anywhere in this component's template:

<div style="width: 100px; height: 100px;" ellipsis>Your very long text</div>

<!-- Or for dynamic content: -->
<div style="width: 100px; height: 100px;" ellipsis [ellipsis-content]="yourDynamicContent"></div>

As you can see, you need to define the dimensions of your element yourself. (ngx-ellipsis doesn't automatically add any element styles.) But of course you don't need to use fixed widths/heights like in these examples. Flex layout shold work just fine for example.

Module import

Should you not be using angular standalone components in your project (available since angular 16), import EllipsisModule in your module instead - see old instructions for an example.

Extra options

You may add the following attributes to change the directive's behavior:

attribute meaning
ellipsis required If you pass an attribute value (e.g. ellipsis=" More ...") you can override the text that will be appended, should it be necessary to truncate the text (default: "...")
ellipsis-content Use this for dynamic content, that will be subject to asynchronous changes (e.g.: [ellipsis-content]="myVar")
ellipsis-word-boundaries If you pass this attribute, the text won't be truncated at just any character but only at those in the attribute's value. For example ellipsis-word-boundaries=" \n" will allow the text to break at spaces and newlines only
ellipsis-substr-fn substr function to use for string splitting. Defaults to the native String#substr. (This may for example be used to avoid splitting surrogate pairs - used by some emojis - by providing a lib such as runes.)
ellipsis-resize-detection How resize events should be detected - these are the possible values: resize-observer: default Use native ResizeObserver - see https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverwindow: Only listen if the whole window has been resized/changed orientation (Possibly better performance, but obviously won't trigger on resize caused directly or indirectly by javascript.)manual: Ellipsis is never applied automatically. Instead the consuming app may use #ell="ellipsis" in the template and this.ell.applyEllipsis() in the component code.
ellipsis-click-more Event emitter - If set, the text defined by the ellipsis attribute will be converted into a clickable link. For example (ellipsis-click-more)="moreClicked()" will call your component's moreClicked() method when the user clicks on the link.
ellipsis-change Event emitter - Will be emitted whenever the ellipsis has been recalculated (depending on ellipsis-resize-detection). If the text had to be truncated the position of the last visible character will be emitted, else null.

Build & publish on npm

In case you want to contribute/fork:

  1. Run npm install
  2. Adept version and author in ./projects/ngx-ellipsis/package.json and ./README.md and commit the changes to your fork.
  3. Run npm run build-lib which outputs the build to ./dist/ngx-ellipsis.
  4. To publish your build, run npm run publish-lib.

Running unit tests

Run npm run test ngx-ellipsis to execute the unit tests via Karma.

License

MIT

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory