I'm new in angular and cloud function. I've created a cloud function to fetch data from Firebase. It is responding correctly in postman.
It's format is as follows:
{
"products": {
"-L7bnFARTPRbuYbPXnVw": {
"createdAt": "Thu Mar 15 2018 09:26:09 GMT+0530 (India Standard Time)",
"image": "https://firebasestorage.googleapis.com/v0/b/sign-up-angular.appspot.com/o/images%2Fbackground1.jpg?alt=media&token=fe96aeab-4f6f-4338-ad08-c3e0da1d610b",
"likes": 1,
"pname": "asdf",
"price": "123"
},
"-L7bnJBfADM_PFVnKo4N": {
"createdAt": "Thu Mar 15 2018 09:26:25 GMT+0530 (India Standard Time)",
"image": "https://firebasestorage.googleapis.com/v0/b/sign-up-angular.appspot.com/o/images%2Fbackground1.jpg?alt=media&token=fe96aeab-4f6f-4338-ad08-c3e0da1d610b",
"likes": 0,
"pname": "asdf",
"price": "123"
}
}
}
I want to retrieve the data and show in angular.
The angular ts & html files are as follows:
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { ProductService } from '../product.service';
import { Observable } from 'rxjs/Observable';
import { Product } from '../product';
@Component({
selector: 'app-data',
templateUrl: './data.component.html',
styleUrls: ['./data.component.css'],
providers: [ProductService]
})
export class DataComponent implements OnInit {
products:Product[];
constructor(private productService: ProductService) { }
ngOnInit() {
this.productService.readProducts()
.subscribe(products =>{
this.products = products['records']
console.log(products);
//On console data are showing properly.
});
}
}
HTML:
<div class="row">
<div class="col-md-12">
<!-- HTML table for our list of product records -->
<table class='table table-hover table-responsive table-bordered'>
<tr>
<th>Product</th>
<th>Price</th>
<th>Like</th>
<th>Image</th>
</tr>
<!-- Use *ngFor directive to loop throught our list of products. -->
<tr *ngFor="let product of products">
<td>{{product.pname}}</td>
<td>{{product.products.pname}}</td>
<td>{{product.price}}</td>
<td>{{product.likes}}</td>
<td>{{product.image}}</td>
</tr>
</table>
</div>
</div>
But it is showing no data.
So please help to show the data in table. Thanks in advance.