I quite new to Angular 5 and AngularFireList I downloaded this starter template
They use a state map in the todos folder where they have push the input value to the database. But I want to push data to the database with the value of input with it.
Here they push data:
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,
});
And here is the this.categoryService.categories()
method:
categories(): AngularFireList<Category> {
return this.db.list(`/restaurants/${this.auth.auth.currentUser.uid}/restaurant_menu/`);
}
Than I create a pages folder my self where I load the categories like this:
categories$ = this.categoriesService.categories().valueChanges();
What I tried is to give the categroy.name
as paramater to categories()
like this:
const ref = this.categoryService.categories(category.name).push({
name: category.name,
description: category.description,
uid: '',
});
And than set the name to the service:
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}`);
}
Than write a function to retrieve the value in the category service like this:
getCategoryName(){
return this.categoryName;
}
And than in the pages folder call the getCategoryName method
categoryName: any = this.categoriesService.getCategoryName();
categories$ = this.categoriesService.categories(categoryName).valueChanges();
But this returns me undefined could someone clear this out or show me how this is done in best practise?