0

I have a list of 4 items, the first 2 visible and the last 2 hidden. And a "show more / less" button that toggles the visibility of the last 2 items.

<ol>
  <li *ngFor="let errorList of errorItems | slice: 0:count">
    <p>{{ errorList }}</p>
  </li>
</ol>
<p *ngIf="errorItems.length > 2" (click)="viewMoreClicked()">view more details</p>

I need view more and view less

Harish S
  • 13
  • 1
  • 5
  • 1
    StackOverflow isn't a code writing service, post what you've tried. P.S. Your `*ngIf` is not going to let you do what you described, you should toggle a "isVisible" property instead – maury844 Jun 22 '20 at 14:21

1 Answers1

1

Try this -

<ol>
  <li *ngFor="let type of items | slice: 0:count">
    <p>{{ type?.value }}</p>
  </li>
</ol>
<p *ngIf="items.length > 2 && count == 2" (click)='count=items.length'>view more details</p>
<p *ngIf="count != 2" (click)='count=2'>view less details</p>

count = 2;

Working Example

Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215