1

I am trying to implement the product list by following the video, but the list doesnt display the products that I have listed in the firebase database. Can someone help?

product-form.component.html

<div class="form-group">
       <label for ="category">Category</label>
        <select id="category" class="form-control">
            <option value=""></option>
            <option *ngFor="let c of categories$ | async" value="c.$key">
                {{ c.name }}
            </option>
        </select>            
</div>

product-form.component.ts

export class ProductFormComponent implements OnInit {
  categories$;
  
  constructor(categoryService: CategoryService) { 
    this.categories$= categoryService.getCategories();
  }

  ngOnInit() {
  }

}

category.service.ts

export class CategoryService {

  constructor(private db:AngularFireDatabase) { }


  getCategories() {
    return this.db.list('/categories');


  }
}

I have manually entered the categories in the firebase realtime database looks like this. categories

Categories in the database

1 Answer 1

2

Try like this:

getCategories() {
    return this.db.list('/categories').snapshotChanges();
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks @adrita, i tried your suggestion. The categories list are now populated with 3 empty values which wasnt displayed previously. However the names aren't displayed.
@IndrajitRavi It's probably because you've stored the names in the objects of the keys.
Could you log what getCategories returns in your component? I haven't used the Realtime Database so I'm not sure as to how your data is actually represented.
@Edric Thank you, i changed it from c.name to c.key in the product-form.html and the list got populated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.