By xnok


2018-09-09 16:16:26 8 Comments

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.

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

<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>

1 comments

@Everton Costa 2018-09-09 18:19:09

The problem is that you don't wrote the function deleteConsulta() or it is missing on the firestoreService file code. And also, you could maybe try to change the access from 'private' to 'public' in the Constructor declarations...

Related Questions

Sponsored Content

2 Answered Questions

[SOLVED] ERROR TypeError: _co.onCLk is not a function

4 Answered Questions

[SOLVED] TypeError: search.valueChanges.debounceTime is not a function

19 Answered Questions

[SOLVED] Angular HTTP GET with TypeScript error http.get(...).map is not a function in [null]

  • 2015-12-29 16:35:48
  • Claudiu
  • 246031 View
  • 334 Score
  • 19 Answer
  • Tags:   angular rxjs

7 Answered Questions

[SOLVED] Are strongly-typed functions as parameters possible in TypeScript?

  • 2013-02-01 02:56:27
  • vcsjones
  • 288927 View
  • 573 Score
  • 7 Answer
  • Tags:   typescript

1 Answered Questions

ERROR TypeError: changes.forEach is not a function

1 Answered Questions

[SOLVED] ERROR TypeError: client.country.map is not a function

1 Answered Questions

AcquireToken Observable errors before returning token

1 Answered Questions

TypeError: someDate.getTime is not a function

Sponsored Content