最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How to reverse order in *ngFor? - Stack Overflow

matteradmin3PV0评论

Please help user order module in *ngFor directive.

I install "ngx-order-pipe": "^1.0.2", and use it in app.module.ts:

import { OrderModule } from 'ngx-order-pipe';
...
..

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    OrderModule,
    ...
    ..
  ],
  providers: [AgendaService],
  bootstrap: [AppComponent]
})
export class AppModule { }

My template:

<div class="line" *ngFor="let line of agenda | orderBy:'order'; let iLine = index">
  <div class="left">
    {{ line.start.trim() }} - {{ line.end.trim() }}  
    = {{line.order}} 
  </div>       
</div>

It worked (lines sorted ascending). But i need lines sorted descending.

I try follow:

<div class="line" *ngFor="let line of agenda | orderBy:'-order'; let iLine = index">
    .....    
</div>

But it not worked.

GITHUB is here

Please help user order module in *ngFor directive.

I install "ngx-order-pipe": "^1.0.2", and use it in app.module.ts:

import { OrderModule } from 'ngx-order-pipe';
...
..

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    OrderModule,
    ...
    ..
  ],
  providers: [AgendaService],
  bootstrap: [AppComponent]
})
export class AppModule { }

My template:

<div class="line" *ngFor="let line of agenda | orderBy:'order'; let iLine = index">
  <div class="left">
    {{ line.start.trim() }} - {{ line.end.trim() }}  
    = {{line.order}} 
  </div>       
</div>

It worked (lines sorted ascending). But i need lines sorted descending.

I try follow:

<div class="line" *ngFor="let line of agenda | orderBy:'-order'; let iLine = index">
    .....    
</div>

But it not worked.

GITHUB is here

Share Improve this question edited Oct 21, 2017 at 10:22 Martin Adámek 18.5k5 gold badges48 silver badges71 bronze badges asked Oct 21, 2017 at 9:33 super.prozandr1super.prozandr1 1273 silver badges10 bronze badges 1
  • How did it not work? What did you expect to happen? What id actually happen? – Lazar Ljubenović Commented Oct 21, 2017 at 9:36
Add a ment  | 

1 Answer 1

Reset to default 3

The ngx-order-pipe has this syntax:

{{ collection | orderBy: expression : reverse }}

So to use descending order, you need to use second parameter:

*ngFor="let line of agenda | orderBy:'order':true; let iLine = index"

More about this on their github:

https://github./VadimDez/ngx-order-pipe

Post a comment

comment list (0)

  1. No comments so far