Open Source Web Application Framework for ASP.NET Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

2.2 KiB

//[doc-seo]
{
    "Description": "Learn how to easily truncate text with ellipsis using the `EllipsisDirective` in ABP Framework, enhancing your Angular templates effortlessly."
}

Ellipsis

Text inside an HTML element can be truncated easily with an ellipsis by using CSS. To make this even easier, you can use the EllipsisDirective which has been exposed by the @abp/ng.theme.shared package.

Getting Started

In order to use the EllipsisDirective in an HTML template, it should be imported in your component. The selector of directive is abpEllipsis. By adding the abpEllipsis attribute to an HTML element, you can activate the EllipsisDirective for the HTML element.

// ...
import { EllipsisDirective } from '@abp/ng.theme.shared';

@Component({
  //...
  imports: [EllipsisDirective],
  template: `
    <p abpEllipsis>
      Lorem ipsum dolor sit, amet consectetur adipisicing elit. Laboriosam commodi quae aspernatur,
      corporis velit et suscipit id consequuntur amet minima expedita cum reiciendis dolorum
      cupiditate? Voluptas eaque voluptatum odio deleniti quo vel illum nemo accusamus nulla ratione
      impedit dolorum expedita necessitatibus fugiat ullam beatae, optio eum cupiditate ducimus
      architecto.
    </p>
  `
})
export class SampleComponent {}

The abpEllipsis attribute has been added to the <p> element that containing very long text inside to activate the EllipsisDirective.

See the result:

Ellipsis directive result

The long text has been truncated by using the directive.

The UI before using the directive looks like this:

Before using the EllipsisDirective

Specifying Max Width of an HTML Element

An HTML element max width can be specified as shown below:

<div [abpEllipsis]="'100px'">
 Lorem ipsum dolor sit amet consectetur adipisicing elit. Cumque, optio!
</div>

<div [abpEllipsis]="'15vw'">
 Lorem ipsum dolor sit amet consectetur adipisicing elit. Cumque, optio!
</div>

<div [abpEllipsis]="'50%'">
 Lorem ipsum dolor sit amet consectetur adipisicing elit. Cumque, optio!
</div>

See the result:

Ellipsis directive result 2