我正在跟踪一个如何使用Firestore进行操作的教程,到目前为止,我一切正常,直到我得到必须从Firestore中删除数据的部分为止,每次我单击它以从Firestore中删除用户时我收到错误消息,说._co.deleteConsulta不是函数,即使它是在我的detailpage.ts中声明的,也没有显示错误,我什至试图运行ionic serve --prod来查看我是否丢失了任何东西,没有任何错误。
对于第二部分,每当我单击删除时,都不会发生 完全没有显示错误。
这是我的详细信息。
import { AlertController } from '@ionic/angular';
import { FirestoreService } from './../../services/data/firestore.service';
import { Consulta } from './../../model/consulta.interface';
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { ActivatedRoute, Router } from '@angular/router';
@Component({
selector: 'app-detail',
templateUrl: './detail.page.html',
styleUrls: ['./detail.page.scss'],
})
export class DetailPage implements OnInit {
public consulta: Observable<Consulta>;
public consultaId;
constructor(private firestoreService: FirestoreService,
private route: ActivatedRoute, private alertController: AlertController, private router: Router) { }
ngOnInit() {
const consultaId: string = this.route.snapshot.paramMap.get('id');
this.consulta = this.firestoreService.getConsultaDetail(consultaId).valueChanges();
}
async deletarConsulta() {
const alert = await this.alertController.create({
message: 'Tem certeza que gostaria de desmarcar sua consulta?',
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: blah => {
console.log('Confirm desmarcação: blah');
},
},
{
text: 'Okay',
handler: () => {
this.firestoreService.deleteConsulta(this.consultaId).then(() => {
this.router.navigateByUrl('');
});
},
},
],
});
await alert.present();
}
}
detail.html
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button></ion-back-button>
</ion-buttons>
<ion-title>{{ (consulta | async)?.unidade }}</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<h3> Unidade </h3>
<p>
Médico{{ (consulta | async)?.medNome }}
</p>
<p> Especialidade{{ (consulta | async)?.especialidade }}</p>
<p> Endereço{{ (consulta | async)?.endereco }}</p>
<p> Data da Consulta {{ (consulta | async)?.data }}</p>
<p> Hora da Consulta {{ (consulta | async)?.hora }}</p>
<ion-button expand="block" (click)="deletarConsulta()">
Desmarcar Consulta
</ion-button>
</ion-content>
答案 0 :(得分:0)
问题是您没有编写函数deleteConsulta()
或firestoreService
文件代码中缺少该函数。而且,您也许可以尝试在构造函数声明中将访问权限从“私有”更改为“公共” ...