[英]*ngIf Firestore with Querying Collections / angularfire2
I am working with Firestore and I need to filter my data by publicado
and sort them by fechaCreacion
. 我与公司的FireStore工作,我需要通过筛选我的数据
publicado
,并通过对它们进行排序fechaCreacion
。 Then I tried this: this.afs.collection ('avisos', ref => ref.where ('publicado', '==', true) .orderBy ('fechaCreacion', 'desc')).valueChanges()
然后我尝试了这个:
this.afs.collection ('avisos', ref => ref.where ('publicado', '==', true) .orderBy ('fechaCreacion', 'desc')).valueChanges()
But it is not allowed by Firestore, according to the documentation. 但是根据文档,Firestore不允许这样做。 Then I was left alone with the order:
this.afs.collection ('avisos', ref => ref.orderBy('fechaCreacion', 'desc')). valueChanges()
然后我就被命令:
this.afs.collection ('avisos', ref => ref.orderBy('fechaCreacion', 'desc')). valueChanges()
this.afs.collection ('avisos', ref => ref.orderBy('fechaCreacion', 'desc')). valueChanges()
and I'm trying to use *ngIf
to show only those where publicado = true
this.afs.collection ('avisos', ref => ref.orderBy('fechaCreacion', 'desc')). valueChanges()
并且我正在尝试使用*ngIf
仅显示那些*ngIf
publicado = true
<div *ngFor="let aviso of avisos | async as aviso" class="col-xl-2 col-lg-3 col-md-4 col-sm-6 col-6 my-1 px-1">
<div *ngIf="aviso.publicado">
<h6>{{ aviso.titulo }}</h6>
<p>{{ aviso.descripcion }}</p>
</div>
</div>
In part, I solve the problem but I have these gaps left. 在某种程度上,我可以解决问题,但我还有这些空白。 How can I solve that?
我该如何解决?
Filter your data inside of your typescript like this: 像这样在打字稿中过滤数据:
this.avisos = this.afs
.collection('avisos', ref => ref.orderBy('fechaCreacion', 'desc'))
.valueChanges()
.map(data => data.filter(d => d.publicado));
Or filter via Firestore in your query (prefered way): 或在查询中通过Firestore过滤(首选方式):
this.avisos = this.afs
.collection('avisos', ref => ref
.orderBy('fechaCreacion', 'desc'))
.where('publicado', '==', true)
.valueChanges();
It's important to order first, and then filter. 重要的是先订购,然后过滤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.