mosh-hamedani / organic-shop

192 stars 204 forks source link

retriving data from firebase when i want display key value #8

Open rajadileepkumar opened 6 years ago

rajadileepkumar commented 6 years ago

retriving data from firebase when i want display key value when i'm using below line [value]="c.$Key" i'm getting undefined message getting

Malikhaseebtahir commented 5 years ago

i have also the same issue

Malikhaseebtahir commented 5 years ago

@rajadileepkumar have you solves this issue ??

danonjam commented 5 years ago

I have the same issue. Is there any update?

Malikhaseebtahir commented 5 years ago

@danonjam Which version of angular you are using ?

danonjam commented 5 years ago

@Malikhaseebtahir Version 7.

danonjam commented 5 years ago

I think @mosh-hamedani Mosh just reply to his students.

mariavkou commented 5 years ago

Hi everyone! This works for me. This is what I did for version 7: at product-form.component.html: <option *ngFor="let c of categories$" [value]="c.name"> {{ c.name }} </option> and then at product-form.component.ts, I defined the categories$ as observable and then subscribed it as below:

import { Observable } from 'rxjs/Observable';
......
export class ProductFormComponent implements OnInit {
  categories$: Observable<any[]>;
 ......
constructor(
private categoryService: CategoryService,....) {

this.categoryService.getAll().valueChanges().subscribe(res => this.categories$ = res as any);
.........
mariavkou commented 5 years ago

When working with a newer version of angular, one temporary good solution is to use this: npm install --save rxjs-compat, which can make your/the "old" (Angular 4) code work.

Have a look here: link

mariavkou commented 5 years ago

Since the '$key' at the new firebase version does not work, you have to find another way to have access at each item. What I did is to create my own id and use it to access the products. At product.service.ts: create(product) { const urlId = new Date().getTime(); return this.db.object('/products/' + urlId).set({ id: urlId, title: product.title, imageUrl: product.imageUrl, category: product.category, price: product.price }); }

I hope this will help.

mudassar2200 commented 4 years ago

retriving data from firebase when i want display key value when i'm using below line [value]="c.$Key" i'm getting undefined message getting this work for me.

getAll(){ return this.db.list('/products').snapshotChanges(); }

 <tr *ngFor="let p of product$ | async" >
        <td>{{p.payload.val().title}}</td>
        <td>{{p.payload.val().price}}</td>
        <td>
            <a [routerLink]="['/admin/products/', p.key]">Edit</a>
        </td>
    </tr>
vinhct99 commented 1 year ago

Hi everyone! This works for me. This is what I did for version 7: at product-form.component.html: <option *ngFor="let c of categories$" [value]="c.name"> {{ c.name }} </option> and then at product-form.component.ts, I defined the categories$ as observable and then subscribed it as below:

import { Observable } from 'rxjs/Observable';
......
export class ProductFormComponent implements OnInit {
  categories$: Observable<any[]>;
 ......
constructor(
private categoryService: CategoryService,....) {

this.categoryService.getAll().valueChanges().subscribe(res => this.categories$ = res as any);
.........

thanks so much