Gbuomprisco / ng2-material-dropdown

Angular 2 Material-like Dropdown Component
MIT License
37 stars 54 forks source link

Get index `onItemClicked`? #31

Closed ClaudiuBadau closed 6 years ago

ClaudiuBadau commented 7 years ago

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>
Esom commented 7 years ago
<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>
Esom commented 7 years ago

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

onItemClicked(month){
    console.log('item clicked ', month);
}
gangsthub commented 6 years ago

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

gangsthub commented 6 years ago

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

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

ClaudiuBadau commented 6 years ago

yep, thank you @gangsthub