Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
ngx-nested-ellipsis
Advanced tools
Library for angular (>= 16.0.0) providing a directive to display an ellipsis if the containing text would overflow.
Supports dynamic html contents. (If you require text contents only, you might want to take a look at ngx-ellipsis, which offers better performance, but escapes any html contents to text.)
For a demo either just checkout this project and run npm install && npm run start
or visit the StackBlitz demo page.
For use in an existing angular project run npm install ngx-nested-ellipsis --save
.
Then add the directive to the component, in which you want to use the ellipsis:
import { NestedEllipsisDirective } from 'ngx-nested-ellipsis';
@Component({
// ...
imports: [
// ...
NestedEllipsisDirective
]
standalone: true
})
export class YourFancyComponent {}
Anywhere in your template:
<div style="width: 130px; height: 18px;">
<ng-template [nestedEllipsis]>Your very long <em>rich</em> text</ng-template>
</div>
As you can see, you need to define the dimensions of your element yourself. (ngx-nested-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.
Should you not be using angular standalone components in your project (available since angular 16), import NestedEllipsisModule
in your module instead - see old instructions for an example.
You may add the following attributes to change the directive's behavior:
attribute | meaning |
---|---|
nestedEllipsis | required Passing true (default) will perform the directive's task otherwise the template will be rendered without truncating its contents. |
nestedEllipsisIndicator | Passing a string (default: '...') will append it when the passed template has been truncated. Passing a template will append that template instead. |
nestedEllipsisWordBoundaries | 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 nestedEllipsisWordBoundaries=" " will allow the text to break at spaces only |
nestedEllipsisMayTruncateAtFn | Function that lets you specify whether the contents may be truncated at a certain point or not. (see callback API) |
nestedEllipsisResizeDetection | How resize events should be detected - these are the possible values:
|
nestedEllipsisChange | Event emitter - Will be emitted whenever the ellipsis has been recalculated (depending on nestedEllipsisResizeDetection ). If the text had to be truncated the position of the last visible character will be emitted, else null . |
Callback function parameters:
name | type | description |
---|---|---|
node | CharacterData | Text node that is checked for truncation |
position | number | Position within that text node where the text might be truncated |
Return true
if truncating at this point in this node should be allowed.
In case you want to contribute/fork:
npm ci
./projects/ngx-nested-ellipsis/package.json
and ./README
and commit the changes to your fork.npm run build-lib
which outputs the build to ./dist/ngx-nested-ellipsis
.npm run publish-lib
.Run npm run test
to execute the unit tests via Karma.
MIT
FAQs
Nested multiline html with ellipsis for angular 16+
The npm package ngx-nested-ellipsis receives a total of 581 weekly downloads. As such, ngx-nested-ellipsis popularity was classified as not popular.
We found that ngx-nested-ellipsis demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.