如何裁剪长文本...离子3

问题描述 投票:1回答:2

enter image description here

下面我有图像的长标题,但我需要修剪,图像没有正确对齐我怎么让它显示效果清晰,同时观看

ionic-framework ionic2 ionic3
2个回答
1
投票

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


3
投票

从去年修剪文本最好的方法是创建自定义管,并使用它。

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

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

© www.soinside.com 2019 - 2024. All rights reserved.