Ionic framework 如何将长文本裁剪为。。。在离子3中

Ionic framework 如何将长文本裁剪为。。。在离子3中,ionic-framework,ionic2,ionic3,Ionic Framework,Ionic2,Ionic3,我在图像下方有一个很长的标题,但我需要修剪它,并且图像没有正确对齐。如何在查看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 cricket

我在图像下方有一个很长的标题,但我需要修剪它,并且图像没有正确对齐。如何在查看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>
Sachin Ramesh Tendulkar是前印度国际板球运动员和前印度国家队队长。
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>
Sachin Ramesh Tendulkar是前印度国际板球运动员和前印度国家队队长。

从最后一个修剪文本的最佳方法是创建自定义管道并使用它

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;
   }
}

然后将此自定义管道注册到模块。您可以在整个应用程序中使用它。

从最后一个修剪文本的最佳方法是创建自定义管道并使用它

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;
   }
}

然后将此自定义管道注册到模块。您可以在整个应用程序中使用它。

是否有任何答案不适用于您的?是否有任何答案不适用于您的?如果use希望显示两行或三行标题,然后显示省略号怎么办?如果use希望显示两行或三行标题,然后显示省略号怎么办?