Search code examples
angularngfor

Angular ngFor for an object


I want to use ngFor to create a dropdown menu depending on my object key. For example

Component.ts

Drop_Down_Menu={1:[1,2,3],2:[3,4,5],3:[4,5,6]}

Component.html

<ng-container *ngFor="let item of Drop_Down_Menu[1]">
    <Label class="donation-label">{{item.value}}</Label>
</ng-container>

my intended output should be a drop-menu with values

1
2
3

Currently

I am getting

1,2,3

all in one row instead of in their own rows


Solution

  • <div class="dropdown-menu">
                        <ng-container *ngFor="let item of Drop_Down_2_Stuff | keyvalue">
                            <div *ngIf="item.key==1">
                                <div *ngFor="let stuff of item.value">
                                    {{stuff}}
                                </div>
                            </div>
                        </ng-container>
                    </div>
    

    @Rihabh thanks