Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ion-item-sliding not working with custom component #7963

Closed
aggarwalankush opened this issue Sep 4, 2016 · 13 comments
Closed

ion-item-sliding not working with custom component #7963

aggarwalankush opened this issue Sep 4, 2016 · 13 comments

Comments

@aggarwalankush
Copy link
Contributor

Short description of the problem:

Using custom component in ion-item-sliding not working, it works with ion-item.
Please refer to below minimal github commit to reproduce issue.

Steps to reproduce:
https://github.com/aggarwalankush/ionic-inappbrowser-issue/commit/50fcae9338d8cb95fceb1cc2904b59a5d37ccc11

Which Ionic Version?
Ionic 2 beta 11

Run ionic info from terminal/cmd prompt: (paste output below)
Your system information:

Cordova CLI: 6.3.0
Gulp version: CLI version 3.9.1
Gulp local: Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.11
Ionic CLI Version: 2.0.0-beta.32
Ionic App Lib Version: 2.0.0-beta.18
ios-deploy version: 1.8.6
ios-sim version: 5.0.8
OS: Mac OS X El Capitan
Node Version: v6.1.0
Xcode version: Xcode 7.3.1 Build version 7D1014

@jgw96
Copy link
Contributor

jgw96 commented Sep 6, 2016

Hello! Thanks for using Ionic! Would you mind trying markup like this

<ion-item-sliding *ngFor="let item of items">
  <!-- move ion-item out of the custom component to here -->
  <ion-item>
    <my-item [item]="item"></my-item>
  </ion-item>
</ion-item-sliding>

@jgw96 jgw96 added the needs: reply the issue needs a response from the user label Sep 6, 2016
@aggarwalankush
Copy link
Contributor Author

Now it displays list but it's now ion-item inside ion-item and creating a weird layout.
See last two rows in below screenshot

screenshot 2016-09-06 10 45 41

@Ionitron Ionitron removed the needs: reply the issue needs a response from the user label Sep 6, 2016
@jgw96
Copy link
Contributor

jgw96 commented Sep 6, 2016

Hello! Would you mind posting the template for you custom component? Thanks!

@jgw96 jgw96 added the needs: reply the issue needs a response from the user label Sep 6, 2016
@aggarwalankush
Copy link
Contributor Author

import {Component, Input} from "@angular/core";
@Component({
  selector: 'my-item',
  template: `<button ion-item>{{item}}</button>`
})
export class ListItemComponent {
  @Input('item') item;
}

Full commit - https://github.com/aggarwalankush/ionic-inappbrowser-issue/commit/50fcae9338d8cb95fceb1cc2904b59a5d37ccc11

P.S. this template is small for demo purpose, in my app, I've big template with ion-avatar and sliding options. Adding ion-item misaligned everything.

@Ionitron Ionitron removed the needs: reply the issue needs a response from the user label Sep 6, 2016
@jgw96
Copy link
Contributor

jgw96 commented Sep 6, 2016

Thanks! Ahh, I see the issue. Could you remove the ion-item attribute from that button? If you still want the item to be clickable (which im guessing you do) then you can change the markup I suggested above to this:

<ion-item-sliding *ngFor="let item of items">
  <button ion-item>
    <my-item [item]="item"></my-item>
  </button>
</ion-item-sliding>

@aggarwalankush
Copy link
Contributor Author

Thanks for quick reply and helping me on this issue.
First of all, I updated the template to be more realistic. Please see commit https://github.com/aggarwalankush/ionic-inappbrowser-issue/commit/d1c1c678ca2b9eb86937e49233e934a19214b1e4

As you can see in commit, I remove ion-item from button and using

 <ion-item-sliding *ngFor="let item of items">
      <button ion-item>
        <my-item [item]="item"></my-item>
      </button>
    </ion-item-sliding>

where my-item is


import {Component, Input} from "@angular/core";
@Component({
  selector: 'my-item',
  template: `
      <button (click)="itemClicked(item)">
        <ion-avatar item-left>
          <img src="img/appicon.png">
        </ion-avatar>
        <h2>{{item|uppercase}}</h2>
        <ion-badge item-right>
            <ion-icon name='happy'></ion-icon>
        </ion-badge>
      </button>
      <ion-item-options>
        <button primary style="width:15vw">
          <ion-icon name="star"></ion-icon>
          <span>Favorite</span>
        </button>
        <button secondary style="width:15vw">
          <ion-icon name="call"></ion-icon>
          <span>Call</span>
        </button>
      </ion-item-options>
`
})
export class ListItemComponent {
  @Input('item') item;

  itemClicked(item) {
    console.log('item clicked - ' + item);
  }
}

It isn't working.

screenshot 2016-09-06 12 45 22

@jgw96
Copy link
Contributor

jgw96 commented Sep 6, 2016

No problem, thanks for all the info! Could you describe exactly what is not working in the above screenshot?

@jgw96 jgw96 added the needs: reply the issue needs a response from the user label Sep 6, 2016
@aggarwalankush
Copy link
Contributor Author

I created the above screenshot with below code


<ion-header>
  <ion-navbar no-border-bottom>
    <ion-title>List</ion-title>
  </ion-navbar>
</ion-header>

<ion-content class="cards-bg">
  <ion-list>

    <!--WORKING-->
    <ion-item-sliding *ngFor="let item of items">
      <button ion-item (click)="itemClicked(item)">
        <ion-avatar item-left>
          <img src="img/appicon.png">
        </ion-avatar>
        <h2>{{item|uppercase}}</h2>
        <ion-badge item-right>
          <ion-icon name='happy'></ion-icon>
        </ion-badge>
      </button>
      <ion-item-options>
        <button primary style="width:15vw">
          <ion-icon name="star"></ion-icon>
          <span>Favorite</span>
        </button>
        <button secondary style="width:15vw">
          <ion-icon name="call"></ion-icon>
          <span>Call</span>
        </button>
      </ion-item-options>
    </ion-item-sliding>

    <!--  ---------THIS IS NOT WORKING------------- -->
    <ion-item-sliding *ngFor="let item of items">
      <button ion-item>
        <my-item [item]="item"></my-item>
      </button>
    </ion-item-sliding>


<!--  ---------THIS IS NOT SHOWING ANYTHING------------- -->
    <ion-item-sliding *ngFor="let item of items">
        <my-item [item]="item"></my-item>
    </ion-item-sliding>

  </ion-list>
</ion-content>

where my-item template is


import {Component, Input} from "@angular/core";
@Component({
  selector: 'my-item',
  template: `
      <button (click)="itemClicked(item)">
        <ion-avatar item-left>
          <img src="img/appicon.png">
        </ion-avatar>
        <h2>{{item|uppercase}}</h2>
        <ion-badge item-right>
            <ion-icon name='happy'></ion-icon>
        </ion-badge>
      </button>
      <ion-item-options>
        <button primary style="width:15vw">
          <ion-icon name="star"></ion-icon>
          <span>Favorite</span>
        </button>
        <button secondary style="width:15vw">
          <ion-icon name="call"></ion-icon>
          <span>Call</span>
        </button>
      </ion-item-options>
`
})
export class ListItemComponent {
  @Input('item') item;

  itemClicked(item) {
    console.log('item clicked - ' + item);
  }
}

We are putting template in <button ion-item> and template has <ion-item-options> also, so you can't slide list item to see options, also everything is misaligned as compare to if we don't use template.

@Ionitron Ionitron removed the needs: reply the issue needs a response from the user label Sep 6, 2016
@vince-nyanga
Copy link

I have a similar issue

@eggplantPrince
Copy link

same issue here!

@Urbiwanus
Copy link

Problem still exists with Version 2.2.0

@brandyscarney
Copy link
Member

This issue goes back to our issues with nested content projection. Basically when you wrap it in a custom component it isn't able to grab the individual components and place them in the correct location inside of the item. I wrote some details on this in this comment: #9080 (comment)

Here is a forum post discussing how item projection works: https://forum.ionicframework.com/t/confused-about-ion-item-usage/54116/10

There is some documentation on item placement here: http://ionicframework.com/docs/api/components/item/Item/#item-placement

I am going to close this issue as it isn't something that we will be able to fix in v3, but it will be fixed in v4. Please see my comment here for more information.

@ionitron-bot
Copy link

ionitron-bot bot commented Sep 2, 2018

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants