Search code examples
ionic-frameworkionic2

Ionic2: How to make the ion-in ion-list item clickable?


I have a page to show a list of branches and select a branch to go to next page.

How to make the ion-item clickable, capture the click and select item?

I tried this code and it works. But, it shows a list of buttons.

 <ion-list>
    <ion-item *ngFor="let branch of branchArray">
       <button ion-button full (click)='goHome(branch)'>
          {{branch.name}}
       </button>              
    </ion-item>
 </ion-list> 

Solution

  • I think buttons getting displayed is an UI issue. Since I do not know the exact requirement of how it should be displayed, check out how to use ion-list here as you want. You can also style it in CSS according to your requirement.

    As far as the clickable part : what you have also works, but, make item clickable like this:

    <ion-list>
        <ion-item *ngFor="let branch of branchArray"  (click)='goHome(branch)'>
            <button ion-button full>
                {{branch.name}}
            </button>             
        </ion-item>
    </ion-list>