I have integrated angularefire into the angular.io 'take a look tutorial' (shopping cart) in order to utilize firebase firestore for products data and orders processing. I have managed to partially replace products.ts and shipping.json, as well as update the message "your order has been submitted" with a dynamic solution. However, there is still an issue that I am facing...
Within cart.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
//angularfire
import { AngularFirestore} from '@angular/fire/firestore';
import { Observable } from 'rxjs';
@Injectable()
export class CartService {
items = [];
//angularfire
fshipping: Observable<any[]>;
afs: AngularFirestore;
constructor(
private http: HttpClient,
//angularfire
firestore: AngularFirestore
) {
this.fshipping = firestore.collection('fshipping').valueChanges();
this.afs = firestore;
}
addToCart(product) {
this.items.push(product);
}
getItems() {
return this.items;
}
clearCart() {
this.items = [];
return this.items;
}
getShippingPrices() {
//angularfire
// return this.http.get('/assets/shipping.json');
return this.fshipping;
}
//angularfire
placeOrder(customerData) {
const orderColl = this.afs.collection<any>('forders');
// const orderColl = this.firestore.collection<any>('forders');
orderColl.add({
name: customerData.name,
address: customerData.address
});
}
}
The implementation of fshipping (within the constructor) successfully replaced shipping.json. However, within the placeOrder method, when I attempted to use this.afs.collection('forders') instead of this.firestorre.collection ..., I encountered the following error:
ERROR in src/app/cart.service.ts:45:28 - error TS2339: Property 'firestore' does not exist on type 'CartService'.
This issue occurred at line 45:
const orderColl = this.firestore.collection<any>('forders');
In my research of other online tutorials, it seems that they were able to seamlessly utilize the firestore instance injected via the constructor in other methods. What could be the missing piece in my case? Thank you.