I would like to make a show less and show more effect using ngFor so that by clicking the see more button, all the texts are expanded and not just one, I want that if the text exceeds for example 150 characters, I apply a part of the text + " ... " and hide the rest of the texts. When I click the see more button, the rest of ALL texts appear, not just one, and the see more button text is changed to see less.
I haven't made much progress, so I don't have a complete code.
<td *ngFor=" let test of testData?.testDataDescription?.testDataDescriptionCode">
<div #myDivText>
{{handleBigText(test?.descriptionArea?.summary, myDivText)}}
</div>
<span #extend
(click)="collapseText( test?.description?.textSumarryDescription, myDivText, extend)">
<img src="/assets/images/arrow_down.svg"/>
view more
</span>
</td>
public maxLength = 150;
public resizeText = 3;
public sizeDescription = this.maxLength;
public sizeDescriptionDots = this.maxLength + this.resizeText;
collapseText(text: string, myDivText: Element, extend: Element) {
const size = text.length - 3;
if (myDivText.innerHTML.length <= size) {
myDivText.innerHTML = text;
extend.innerHTML = `<img src="/assets/images/arrow_up.svg" />
see less`;
} else {
myDivText.innerHTML = `${text.substring(0, this.sizeDescriptionDots)}...`;
extend.innerHTML = `<img src="/assets/images/arrow_down.svg"/>
view more`;
}
}
handleBigText(text: string, myDivText: Element) {
if (text) {
const textSize = this.maxLength + this.resizeText;
this.sizeDescription = textSize;
this.sizeDescriptionDots = textSize;
return text.length > textSize
? `${text.substring(0, textSize)}...`
: text;
}
return '-';
}