Gbuomprisco / ng2-material-dropdown

Angular 2 Material-like Dropdown Component

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get index `onItemClicked`?

ClaudiuBadau opened this issue · comments

commented

Not sure if this is possible but I have a dropdown with months and I want to be able to get the current month when I click on the item, is this possible?

  <ng2-dropdown (onItemClicked) = onItemClicked()>
    <ng2-dropdown-button>
      {{ currentMonth }}
    </ng2-dropdown-button>
    <ng2-dropdown-menu>
      <ng2-menu-item *ngFor="let month of months">
        {{ month }}
      </ng2-menu-item>
    </ng2-dropdown-menu>
  </ng2-dropdown>
commented
<ng2-dropdown>
    <ng2-dropdown-button>
      {{ currentMonth }}
    </ng2-dropdown-button>
    <ng2-dropdown-menu>
      <ng2-menu-item *ngFor="let month of months" (click) = onItemClicked(month)>
        {{ month }}
      </ng2-menu-item>
    </ng2-dropdown-menu>
  </ng2-dropdown>

commented

in your controller create a method with an onItemClicked() method with a parameter

onItemClicked(month){
    console.log('item clicked ', month);
}

@ClaudiuBadau is it ok to close this one? ;)

and you where also missin the propper syntax for the snippet: it should be:

<ng2-dropdown (onItemClicked)="onItemClicked()">

commented

yep, thank you @gangsthub