我对Angular 5和AngularFireList很新,我下载了this starter template
他们在todos文件夹中使用状态映射,他们将输入值推送到数据库。但我想用数据输入值将数据推送到数据库。
他们推送数据:
const ref = this.categoryService.categories().push({
name: category.name,
description: category.description,
uid: '',
});
return ref.set({
name: category.name,
description: category.description,
uid: ref.key,
});
这是this.categoryService.categories()
方法:
categories(): AngularFireList<Category> {
return this.db.list(`/restaurants/${this.auth.auth.currentUser.uid}/restaurant_menu/`);
}
我创建了一个自己的页面文件夹,我加载了这样的类别:
categories$ = this.categoriesService.categories().valueChanges();
我尝试的是将categroy.name
作为categories()
的参数,如下所示:
const ref = this.categoryService.categories(category.name).push({
name: category.name,
description: category.description,
uid: '',
});
然后将名称设置为服务:
categoryName: any;
categories(category_name): AngularFireList<Category> {
this.categoryName = category_name
//HERE I WOULD LIKE TO USE THE CATEGORY_NAME TO NEST IT IN RESTAURANT_MENU
return this.db.list(`/restaurants/${this.auth.auth.currentUser.uid}/restaurant_menu/${category_name}`);
}
比编写一个函数来检索类别服务中的值,如下所示:
getCategoryName(){
return this.categoryName;
}
并且在页面文件夹中调用getCategoryName method
categoryName: any = this.categoriesService.getCategoryName();
categories$ = this.categoriesService.categories(categoryName).valueChanges();
但是,如果有人清楚这一点,或者告诉我这是如何在最佳实践中完成的,那么这会让我不确定吗?