My application structure has 1 service and 2 components:
Service: Holds all of the firestore connections ViewComponent: Gets a list from the service and displays it ItemManagementComponent: Displays a form and allows the user to add a new entry.
The Issue I have a button in the ViewComponent that (in theory), sends a documentID to the ManagementComponent which then displays that document data in the form, allowing for a user update. Right now, when I click the button I can track the doumentID, and the service return all the way through my application, but I'm not actually getting a document returned. I can run the exact same code with a hardwired documentID, and it works great, so obviously I'm missing something.
Service
getUpdateInventoryItem(updateId: string) {
console.log('service', updateId)
this.updateId = updateId
console.log('service2', this.inventoryCollectionRef.doc(updateId).ref.get())
return this.inventoryCollectionRef.doc(updateId).ref.get()
}
View HTML
<td><button type="button" class="btn btn-default" (click)="updateInventory(item.id)">Upd</button></td>
<app-item-management [updateID]="ChildUpdateId"></app-item-management>
View Component
@Output() inventoryUpdate = new EventEmitter();
public ChildUpdateId: string;
updateInventory(updateId: string) {
this.ChildUpdateId = updateId;
}
ItemManagement Component
@Input() updateID;
ngOnChanges(incomingID: SimpleChanges) {
if (!incomingID['updateID'].isFirstChange()) {
for (let ID in incomingID) {
let chng = incomingID[ID];
let cur = JSON.stringify(chng.currentValue);
console.log('current', cur)
this.updateInventory(cur)
}
}
}
updateInventory(incomingID) {
console.log('updateFunction',incomingID)
this.inventoryService.getUpdateInventoryItem(incomingID)
.then((doc) => {
if (doc.exists) {
this.editItem = doc.data();
this.inventoryForm.patchValue(this.editItem);
this.update = true;
} else {
console.log("No such document!");
}
}).catch(function (error) {
console.log("Error getting document:", error);
});
};
So, if I click on the update button on the view HTML, this is what my console shows me: console log screenshot From my perspective, I'm seeing the ID passed to the service, and the service has a properly formatted document response to return.
If I copy a document ID directly from my console log and hardwire it to the updateInventory function on the ItemManagementComponent, and call the hardwired function from the NgOnChanges it works. It's just that somehow when I'm passing in this ID as a variable it's short circuiting.
I had this same updateInventory function working with a slightly different implementation that took a variable, so I'm really stumped. Any help is greatly appreciated!