I'm currently working on retrieving the id of selected data, but when I test it using console.log, it keeps outputting twice. The image below illustrates the console.log output.
https://i.stack.imgur.com/IARng.png
My goal is to fetch the id once and then transfer it to another collection using the archive method instead of delete. Although I've successfully copied it to another table, it ends up being duplicated, hence why I am testing it in the console first.
Below are my code snippets for handling a click on the delete button:
employee.service.ts
import { Injectable } from '@angular/core';
import { AngularFirestore } from '@angular/fire/compat/firestore';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class EmployeeService {
constructor(private firestore: AngularFirestore) { }
deleteEmployee(id: string): Promise<any> {
return this.firestore.collection('employees').doc(id).delete();
}
}
list-employees.component.ts
deleteEmployee(id: string) {
this._employeeService.getEmployee(id).subscribe(data => {
console.log(id);
})
}
I would greatly appreciate any assistance and please let me know if additional code is needed for reference. Thank you!