Reputation: 209
I am trying to list the product in an HTML. But the record is not being showed and at the same time the the product list can be seen in JavaScript message. Please somebody can help me to list the record in an html file . Here is my code in app.component.ts
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'Skinet';
products: any[]=[];
constructor(private http: HttpClient){}
ngOnInit(): void {
this.http.get('https://localhost:5001/api/products').subscribe((Response: any) => {
this.products = Response.data;
console.log(Response.data);
}, error => {
console.log(error);
})
}
}
In app.component.html
<app-nav-bar></app-nav-bar>
<div class="container" style="margin-top: 140px;">
<h1>Welcomes to {{title}}!</h1>
<ul>
asd
<li class="list-unstyled" *ngFor="let product of products"> <!-- the Product is not coming -->
</li>
</ul>
</div>
Upvotes: 0
Views: 204
Reputation: 1656
You are not displaying anything from the productList.
<ul>
asd
<li class="list-unstyled" *ngFor="let product of products">
{{product.<attributeName>}}
</li>
</ul>
Additional Recommendations
products: ProductInfo[] = [];
. TypeScript allows your JavaScript code to be strongly typed. Take advantage of that feature. Can save you tons of debug time.https://angular.io/guide/styleguide
Upvotes: 1