我有两个共享相同服务的组件。
我正在尝试让该组件将单击项的ID发送给服务,因此当它路由到其他组件时,它将显示单个文档。
产品列表组件:
sendId(id: string) {
this.productService.sendId(id);
this.route.navigate(['/page']);
}
产品服务:
export class ProductService {
productDoc: AngularFirestoreDocument<Product>;
products: Observable<Product[]>;
product: Observable<any>;
aProduct: Product;
id: string;
constructor(public afs: AngularFirestore) {
this.productDoc = this.afs.doc<Product>('products/' + this.id);
this.product = this.productDoc.valueChanges();
this.product.subscribe((product) => (this.aProduct = product));
}
sendId(id: string) {
this.id = id;
console.log(this.id);
}
getProduct() {
return this.aProduct;
}
提前谢谢!