我正在使用* ngFor重复json数组,我想检查{{a.body}}的文本长度。如果它大于20,那么在结束时追加三重周期(点)。
EG。如果我的文字是"你好吗约翰?让我们度过一个晚上喝啤酒"
我希望输出是"你好吗约翰?勒..."
<md-card class="example-card1" *ngFor="let a of data">
<md-card-header>
<div md-card-avatar class="example-header-image"></div>
<md-card-title>{{a.name}}</md-card-title>
<md-card-subtitle>{{a.email}}</md-card-subtitle>
</md-card-header>
<img md-card-image src="https://material.angular.io/assets/img/examples/shiba2.jpg" alt="Photo of a Shiba Inu">
<md-card-content>
<p>
{{a.body}}
</p>
</md-card-content>
<md-card-actions>
<button md-button>LIKE</button>
<button md-button>SHARE</button>
</md-card-actions>
</md-card>
&#13;
答案 0 :(得分:0)
您应该像这样写code
:
<md-card class="example-card1" *ngFor="let a of data">
<md-card-header>
<div md-card-avatar class="example-header-image"></div>
<md-card-title>{{a.name}}</md-card-title>
<md-card-subtitle>{{a.email}}</md-card-subtitle>
</md-card-header>
<img md-card-image src="https://material.angular.io/assets/img/examples/shiba2.jpg" alt="Photo of a Shiba Inu">
<md-card-content>
<p>
{{ a.body.length > 20 ? a.body.substring(0,20) + ' ...' : a.body }}
</p>
</md-card-content>
<md-card-actions>
<button md-button>LIKE</button>
<button md-button>SHARE</button>
</md-card-actions>
</md-card>