[英]ERROR TypeError: _co.deleteConsulta is not a function
i was following a tutorial how to make a crud using firestore, and thus far i got everything working right until i got the part that i had to delete the data from firestore, everytime i click it to delete an user from my firestore i get the error saying that ._co.deleteConsulta is not a function, even though it was declared inside my detailpage.ts, and it shows no error, i even tried to run ionic serve --prod to see if i was missing anything, no errors whatsoever. 我正在按照教程学习如何使用Firestore进行分类,到目前为止,我一切正常,直到我得到必须从Firestore删除数据的部分,每次我单击以从Firestore中删除用户时,我都会错误说._co.deleteConsulta不是一个函数,即使它是在我的detailpage.ts中声明的,也没有显示错误,我什至试图运行ionic serve --prod来查看我是否丢失了任何东西,没有任何错误。
For the second part whenever i click delete, nothing happens no errors are shown at all. 对于第二部分,每当我单击“删除”时,都不会发生任何错误,不会显示任何错误。
here's my detail.ts 这是我的细节
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 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>
The problem is that you don't wrote the function deleteConsulta()
or it is missing on the firestoreService
file code. 问题是您没有编写函数
deleteConsulta()
或在firestoreService
文件代码中缺少该函数。 And also, you could maybe try to change the access from 'private' to 'public' in the Constructor declarations... 而且,您也许可以尝试在构造函数声明中将访问权限从“私有”更改为“公共” ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.