I am dealing with JSON data that contains nested arrays and objects, specifically
Stores[]--->Products[]--->ProductDetails--->ProductTags[]
. Initially, I want to display all the data by writing the following code:
service
export class StoreService {
//private myurl: string ="apidata/products.json"
constructor(private _http: Http) {}
getProducts(): Observable < any > {
let apiUrl = './assets/products.json';
return this._http.get(apiUrl)
.pipe(map((response: Response) => {
const data = response.json();
return data;
}));
}
store component:
export class StoreComponent implements OnInit {
products = [];
constructor(private _storeService: StoreService) {}
ngOnInit() {
this._storeService.getProducts()
.subscribe(data => {
this.products = data;
console.log(data)
});
}
}
html
<h2>store</h2>
<ul>
<li *ngFor="let p of products">{{p}}</li>
</ul>
However, when trying to render the data, I encounter the following error:
Error trying to diff '[object Object]'. Only arrays and iterables are allowed