prince s
prince s

Reputation: 105

How to crop the long text as ... in ionic 3

enter image description here

I have a long tittle below image but I need to trim it and the image is not properly aligned how do I make it appear clear while viewing

Upvotes: 1

Views: 1008

Answers (2)

Hardik
Hardik

Reputation: 3258

Best way to trim text from last is to create your custom pipe and use it.

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
 name: 'trimLast'
})

export class TrimLastPipe implements PipeTransform {

transform(value: string, args: string[]): string {
    const limit = args.length > 0 ? parseInt(args[0], 10) : 20;
    const trail = args.length > 1 ? args[1] : '...';
    return value.length > limit ? value.substring(0, limit) + trail : value;
   }
}

and then register this custom pipe to module. you can use it in entire application.

Upvotes: 3

Sudarshana Dayananda
Sudarshana Dayananda

Reputation: 5265

CSS

.wrap-text {
  width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

HTML

<h4 class="wrap-text">Sachin Ramesh Tendulkar is a former Indian international cricketer and a former captain of the Indian national team.</h4>

working demo

Upvotes: 2

Related Questions