Get index `onItemClicked`?
ClaudiuBadau opened this issue · comments
Claud 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>
Esom 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>
Esom commented
in your controller create a method with an onItemClicked() method with a parameter
onItemClicked(month){
console.log('item clicked ', month);
}
Paul Melero commented
@ClaudiuBadau is it ok to close this one? ;)
Paul Melero commented
and you where also missin the propper syntax for the snippet: it should be:
<ng2-dropdown (onItemClicked)="onItemClicked()">
Claud commented
yep, thank you @gangsthub