How to populate drop-down menu with items from array

Viewed 106

i am trying to populate the dropdown menu with items from an array as shown below in the code. when i run the app i just receive a button with text and clr-dropdown but no items show up

please let me know how to populate dropdown-menu with items from array

code:

<clr-dropdown>
            <button class="dropdown-toggle btn btn-primary">
                {{ "SITE.INSECTICIDES.TYPES_LABEL" | translate }} 
                <clr-icon shape="caret down"></clr-icon>
                <clr-dropdown-menu clrPosition="top-left">
                    <div class="dropdown-menu" *ngFor="let pesticide of pesticidesArray">
                        {{pesticide}}
                    </div>
                </clr-dropdown-menu>
            </button>
        </clr-dropdown>
        

ts:

  export class InesecticidesTypesAndDosesComponent implements OnInit {
  isBackDropModalVisible=false;
  modalContentVisible =false
  pesticidesArray = new Array();

  constructor() { 
    this.pesticidesArray = new Array();
    this.pesticidesArray.push(environment.Pesticide_type1)
    this.pesticidesArray.push(environment.Pesticide_type2)
    this.pesticidesArray.push(environment.Pesticide_type3)
    this.pesticidesArray.push(environment.Pesticide_type4)
    this.pesticidesArray.push(environment.Pesticide_type5)
  }

  ngOnInit(): void {
  }
1 Answers

i found the answer. i just had to add *clrIfOpen and clrDropdownItem

code:

<clr-dropdown>
            <button class="dropdown-toggle btn btn-primary" clrDropdownTrigger>
                {{ "SITE.INSECTICIDES.TYPES_LABEL" | translate }} 
                <clr-icon shape="caret down"></clr-icon>
            </button>
            <clr-dropdown-menu *clrIfOpen clrPosition="bottom-left">
                <div aria-label="Dropdown header" *ngFor="let pesticide of pesticidesArray" clrDropdownItem>
                    {{pesticide}}
                </div>
            </clr-dropdown-menu>
        </clr-dropdown>
Related