【发布时间】:2018-07-19 08:36:11
【问题描述】:
我收到了来自 服务器 的 api 响应,其中包含一个具有长文本的属性。我想以一种简单的方式正确截断它们,我使用了这个package。
这是我的 html
中的代码<ion-card class="pin" *ngFor="let item of winner">
<div class="wrapper" (tap)="onView(item)">
<img [src]="item?.image | image:'300'" class="img" />
</div>
<button ion-button clear icon-only item-start class="profile">
<ion-avatar item-start>
<img [src]="" height="30" class="img-avatar" onError="this.src='https://vollrath.com/ClientCss/images/VollrathImages/No_Image_Available.jpg';">
</ion-avatar>
<ion-card-title ion-text color="textBlack"> {{item?.name?.firstName}} {{item?.name?.lastName}}
</ion-card-title>
</button>
<p class="card-subtitle" *ngIf="item?.comment?.length >= 100" text-wrap>{{item?.comment | truncate : 100}}</p>
<button ion-button full small block *ngIf="truncating && item.comment.length > 100" (tap)="truncating = false">
Read More
</button>
<button ion-button full small block *ngIf="!truncating && item.comment.length > 100" (tap)="truncating = true">
Show Less
</button>
</ion-card>
在我的 ts 文件中
import { TruncateModule } from '@yellowspot/ng-truncate';
truncating = true;
我在这里没有任何错误,但截断正在工作,但在数组的所有元素上。
如何为数组中的特定item触发和截断comment?
如果有人可以提供帮助,我们将不胜感激。 提前致谢。
【问题讨论】:
标签: angular ionic-framework ionic3 truncate truncation