Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

264
Visualizações
aplicar mostrar más y mostrar menos efecto usando ngFor, para que muestre el resto de todo el texto en la lista y no solo uno

Me gustaria hacer un show menos y mostrar mas efecto usando ngFor para que al hacer clic en el boton ver mas se expandan todos los textos y no solo uno, quiero que si el texto excede por ejemplo 150 caracteres, aplique una parte de el texto + "..." y ocultar el resto de los textos. Cuando hago clic en el botón ver más, aparece el resto de TODOS los textos, no solo uno, y el texto del botón ver más se cambia para ver menos.

No he progresado mucho, así que no tengo un código completo.

 <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 '-'; }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Estás complicando demasiado esto. No es necesario modificar el texto original en sí.

  1. Usemos Angular | slice la tubería para limitar el texto que se muestra. https://angular.io/api/common/SlicePipe

  2. *ngIf para mostrar condicionalmente más o menos texto.

 <hello name="{{ name }}"></hello> <p> {{ showMore ? text : (text | slice: 0:150) }} <span *ngIf="!showMore">...</span> <a href="javascript:;" *ngIf="!showMore" (click)="onShow()">[Show More]</a> <a href="javascript:;" *ngIf="showMore" (click)="onShow()">[Show Less]</a> </p>
 @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class AppComponent { name = 'Angular'; showMore = false; onShow () { this.showMore = !this.showMore; } text = `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`; }

Ejemplo de trabajo: https://stackblitz.com/edit/angular-easy-show-more-6ispwx?file=src%2Fapp%2Fapp.component.html

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda