我正在从名为“ prescription”的Firebase文档中访问数据,但是,我是angular的新手,我无法提出一种解决方案来过滤数据(start_date,date_final,patient_name和name_prescription)。我正在为移动设备ionic4使用框架。
HTML =>
<ion-list>
<ion-item *ngFor="let prescricao of filteredPrescricoes">
<ng-container *ngIf="prescricao.nome !== ''; else elseTemplate">
<ion-label> {{ prescricao.nome }} </ion-label>
</ng-container>
<ng-template #elseTemplate>
<ion-label>Prescrição sem nome</ion-label>
</ng-template>
</ion-item>
</ion-list>
TypeScript =>
ngOnInit() {
this.firestoreService
.getCollection('prescricao')
.pipe(takeUntil(this.unsubscribeAll))
.subscribe(prescricao => {
this.prescricoes = prescricao;
this.loading = false;
this.filteredPrescricoes = this.prescricoes;
});
}
public getCollection(coll: string, where?: any): Observable<any[]> {
if (where) {
return this._angularFirestore.
collection(this._collections.getColl(coll),
ref => ref.where(where.field, '==', where.value)).
snapshotChanges().pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data() as any;
data.id = a.payload.doc.id;
return data;
}))
);
} else {
return this._angularFirestore.
collection(this._collections.getColl(coll)).
snapshotChanges().pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data() as any;
data.id = a.payload.doc.id;
return data;
}))
);
}
}
const alert = await this._alertController.create({
header: 'Filtro',
cssClass: 'ion-text-center',
inputs: [
{
placeholder: 'Data inicial',
label: 'Data inicial',
name: 'data_inicial',
type: 'date'
},
{
placeholder: 'Data final',
label: 'Data final',
name: 'data_final',
type: 'date'
},
{
placeholder: 'Nome do paciente',
label: 'Informe o nome do paciente',
name: 'nome_paciente',
type: 'text'
},
{
placeholder: 'Nome da prescrição',
label: 'Informe o nome do prescrição',
name: 'nome_prescricao',
type: 'text'
}
],
buttons: [
{
text: 'Filtrar',
handler: (data) => {
if (data.data_inicial
&& data.data_final) {
const dataInicial = this.datePipe.transform(data.data_inicial, 'dd-MM-yyyy');
const dataFinal = this.datePipe.transform(data.data_final, 'dd-MM-yyyy');
}
}
}
]
});
await alert.present();
}
我需要他只给我带来期限在初始日期至最终日期之间的处方,并注明患者姓名和处方名称。