如何在 Angular 8 中对 HTML 文件中的字符进行切片和显示

How to Slice character and display in HTML file in Angular 8

我有以下字符串,我在 HTML 文件中显示 Api 响应。

For ex - Test,Abc,Red,blue,Green

displayFull() {
   this.enumValues = this.fullText;
} 

getData() {   
  this.service.getDetails(this.id).subscribe((response: any) => {
    if (response && response.data) {
    this.fullText = response.data; // declare fullText on the top of the class else this will show error.
    this.enumValues = this.fullText.length > 10 ? this.fullText.slice(0, 10): this.fullText; // Add "+ '...'" if you want to add eclipses.
  }
});

}

在HTML

<p class="break-word-text">
   {{enumValues}}
</p>
<a href="#" *ngIf="enumValues !== fullText" (click)="displayFull()">View More</a>
<p class="break-word-text" >
    <span *ngIf="enumValues && enumValues.length > 10">{{enumValues.slice(0, 10)}} <a href="#" title="{{enumValues}}">View more</a></span>
    <span *ngIf="enumValues && enumValues.length <= 10">{{enumValues}}</span>
</p>