Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 在angularfire2 AngularFire6中反转可观测阵列_Firebase_Firebase Realtime Database_Angularfire2 - Fatal编程技术网

Firebase 在angularfire2 AngularFire6中反转可观测阵列

Firebase 在angularfire2 AngularFire6中反转可观测阵列,firebase,firebase-realtime-database,angularfire2,Firebase,Firebase Realtime Database,Angularfire2,我正在使用一个可观测的数组来获取实时数据。数据以升序出现,但我需要它以相反的顺序显示。internet上的示例在angular 5之前,语法不再有效。请告知 html 刷新卡片(){ this.cards=this.dataSvc.fetchCards()管道( map((cards:any)=>cards.map(cardObj=>新卡(cardObj.key,cardObj.\u frontImageUrl,cardObj.\u backImageUrl,cardObj.\u status

我正在使用一个可观测的数组来获取实时数据。数据以升序出现,但我需要它以相反的顺序显示。internet上的示例在angular 5之前,语法不再有效。请告知

html


刷新卡片(){
this.cards=this.dataSvc.fetchCards()管道(
map((cards:any)=>cards.map(cardObj=>新卡(cardObj.key,cardObj.\u frontImageUrl,cardObj.\u backImageUrl,cardObj.\u status,cardObj.\u date,cardObj.\u userId,cardObj.\u message)))
);
}
调用firedb

fetchCards(){
    this.cardList = this.db.list<Card>('adminCardQueue', ref => ref.orderByChild('_date').limitToLast(50))

    return this.cardList.snapshotChanges().pipe(
       map(changes => 
        changes.map(c => ({ key: c.payload.key, ...c.payload.val()}))
       )
      ) ;
  }
fetchCards(){
this.cardList=this.db.list('adminCardQueue',ref=>ref.orderByChild('u date')。limitToLast(50))
返回此.cardList.snapshotChanges().pipe(
映射(更改=>
map(c=>({key:c.payload.key,…c.payload.val()}))
)
) ;
}

您可以使用.slice().reverse()在*ng处反转数组


.slice()创建数组的副本,.reverse()对数组执行反向操作。

您可以使用---


嘿,您是否尝试使用.slice().reverse()反转*ngs处的数组?例:让卡片的(posts | async)?.slice().reverse()让它工作起来。u没有使用.slice()添加那个worked让我把它放在一个答案中以便可见
fetchCards(){
    this.cardList = this.db.list<Card>('adminCardQueue', ref => ref.orderByChild('_date').limitToLast(50))

    return this.cardList.snapshotChanges().pipe(
       map(changes => 
        changes.map(c => ({ key: c.payload.key, ...c.payload.val()}))
       )
      ) ;
  }
<tr *ngFor="let card of (cards | async)?.slice().reverse();let last = last ">
*ngFor="let item of items.slice().reverse()"