-1

I'm trying to display the failedjobs array<any> data in a reverse manner

<ion-item *ngFor="let failjob of failedjobs.slice().reverse()">   

I'm getting an error as

ERROR TypeError: _co.failedjobs.slice is not a function at Object.eval [as updateDirectives] (FailedPage.html:13) at Object.debugUpdateDirectives [as updateDirectives] (core.js:14655) at checkAndUpdateView (core.js:13802) at callViewAction (core.js:14153) at execComponentViewsAction (core.js:14085) at checkAndUpdateView (core.js:13808) at callViewAction (core.js:14153) at execEmbeddedViewsAction (core.js:14111) at checkAndUpdateView (core.js:13803) at callViewAction (core.js:14153)

What is the problem & how do I resolve it.

raj_tx
  • 229
  • 1
  • 5
  • 18
  • please provide minimal verifiable code... – ashish pal Dec 18 '18 at 13:38
  • Whatever `failedjobs` is (and we have no way of telling), it doesn't have a `slice` method. Why do you think it should? – Quentin Dec 18 '18 at 13:40
  • You've tagged this [tag:ionic2] and [tag:ionic3] which are mutually exclusive. Which one are you using? – Quentin Dec 18 '18 at 13:41
  • I'm using ionic 3. I have scene `.slice().reverse()` in some of the post of stackoverflow & I have tried it. Intailly it worked but now it's displaying as error @Quentin – raj_tx Dec 18 '18 at 13:45

1 Answers1

-1

You can use the Slice pipe or use custom pipe instead of calling the function slice().reverse()

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({ name: 'reverse' })

export class ReversePipe implements PipeTransform {
  transform(value) {
    return value.slice().reverse();
  }
}

and consume as

<ion-item *ngFor="let failjob of failedjobs | reverse">   
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396