Untitled
unknown
plain_text
22 days ago
799 B
2
Indexable
Never
fichier sort-by-notes.pipe.ts import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'sortByNotes' }) export class SortByNotesPipe implements PipeTransform { transform ( students: any[]) : any[] { return students.sort((a:any, b:any) => {return b.note - a.note}); } } notes.component.html <h2>Voici les notes des élèves</h2> <ul> <li *ngFor="let note of (notes | sortByNotes)">{{note.note}} </li> </ul> notes.component.ts import { Component } from '@angular/core'; @Component({ selector: 'app-notes', templateUrl: './notes.component.html', styleUrl: './notes.component.css' }) export class NotesComponent { notes =[ {note: 15}, {note: 10}, {note: 5}, {note:8}, {note:3}, {note: 18}, ] }
Leave a Comment