26

Using the Angular2 pipe slice I can do something like this to only show the first five elements of my items.

<ion-item *ngFor='let item of items | slice:0:5">

How can I use variables instead of hardcoding 0 and 5? I want to do something like this and define start and end in my *.ts file.

<ion-item *ngFor='let item of items | slice:"start":"end"'>
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
Jane Dawson
  • 693
  • 2
  • 7
  • 19
  • 5
    use it without double quotes `` – Sachila Ranawaka Jul 06 '17 at 09:14
  • Thank you. I accidently put an "start : 0" and "end : 5" in my *.ts file instead of "start = 0" and "end = 5". Then it didn't work obviously...When I corrected this it worked just fine without the quotes - as you said. Thanks! – Jane Dawson Jul 06 '17 at 09:22

2 Answers2

39

Just remove "(double quotes) from the start and end variable

<ion-item *ngFor='let item of items | slice:start:end'>
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
0

For the slice: 0:5 does not work. here is my solution

 <div class="symbol-group symbol-hover" 
                            *ngFor='let memebr of group?.Members.slice(0,5); let j=index,let y=last'>
            </div>
Zia Khan
  • 188
  • 2
  • 9