gpt4 book ai didi

angular - Ionic 4 如何显示更多/更少的文字?

转载 作者:行者123 更新时间:2023-12-02 00:10:59 33 4
gpt4 key购买 nike

我需要显示文本,但分两行,但是当用户单击“显示更多”时,他/她可以看到所有文本。这是我的代码

   <div *ngFor="let x of announcement">
<ion-card class="group-box">
<div text-left style="font-size: 16px; font-weight: bold; color: white; top: 10%;position: relative; margin-left: 10px;">
{{x.announcementTitle}}
</div>
<div class="" text-left style="font-size: 16px; font-weight: bold; color: white; top: 25%;position: relative; margin-left: 10px;">
{{x.announcementDetails}}
</div>

<div text-right class="announcement-username">
{{x.createrName}}
</div>
</ion-card>
</div>

我需要在 annoucementDetails 中添加 seemore/less 选项

最佳答案

像这样尝试:

Working Demo

.html

<div *ngFor="let x of announcement">
<ion-card class="group-box">
<div>
{{x.announcementTitle}}
</div>
<div>
<div *ngIf="!x.showMore">
{{trimString(x.announcementDetails,100)}}
</div>
<div *ngIf="x.showMore">
{{x.announcementDetails}}
</div>
<a (click)="x.showMore = !x.showMore">Show <span [innerHtml]="x.showMore ? 'less' : 'More'"> </span>
</a>
</div>

<div text-right class="announcement-username">
{{x.createrName}}
</div>
</ion-card>
</div>

.ts

 constructor() {
this.announcement = this.announcement.map(item => ({
...item,
showMore:false,
}));
}

trimString(string, length) {
return string.length > length ?
string.substring(0, length) + '...' :
string;
}

关于angular - Ionic 4 如何显示更多/更少的文字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59126898/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com