D
D
Drovosek012018-08-13 19:10:18
Angular
Drovosek01, 2018-08-13 19:10:18

How to display ngFor under a certain element of another ngFor?

There is such a code

<div class="middle-content" *ngFor="let year of years">
    <a class="middle-content_top-indent" (click)="log(year)">{{year}}</a>
    
    <ul class="list-of-month" *ngFor="let month of months">
      <li>
        <span class="list-of-month__marker"></span>
        <a href="#">{{month}}</a>
      </li>
    </ul>
</div>

That is, the enumeration of years, and under each year the enumeration of months:
5b71ad26949b7406037806.png
You need to display the enumeration of months, only under a certain year.
How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-08-13
@Drovosek01

As far as I understand, the list of months should expand by clicking on the year. Add the activeYear property, make the appropriate assignment in the click handler, and add to the list of months (by the way, you have a bug there - the list element is not ul, but li, so ngFor should be moved) add *ngIf="year === activeYear". Like so .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question