Can somebody please help me how to make an accurate http request using angular? not even chat gpt can do this right, i sent the code and it doesnt know how to fix it
HTML
<h1>Products</h1>
<div *ngFor="let product of products">
<div class="card">
<h3>{{ product.title }}</h3>
<p>{{ product.description }}</p>
<strong>R$ {{ product.price }}</strong>
</div>
<p>Total: {{ products.length }}</p>
</div>
TS
import { Component, OnInit, signal } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Product } from '../product';
import { ProductService } from './apiservice';
@Component({
selector: 'app-root',
standalone: true,
imports: [CommonModule],
templateUrl: './app.html',
styleUrls: ['./app.css'],
})
export class App implements OnInit {
constructor(private productService: ProductService) {
console.log('App constructor executed');
}
protected readonly title = signal('angular-cart');
products: Product[] = [];
ngOnInit(): void {
console.log('ngOnInit executed');
this.loadProducts();
}
loadProducts(): void {
console.log('Calling loadProducts');
this.productService.getProducts().subscribe({
next: (response) => {
console.log('API response:', response);
this.products = response.products;
console.log('Products set:', this.products);
},
error: (error) => console.log('Request error:', error),
});
}
}
BTW the console shows no errors. It shows the http sequest as sucessful in the console, but nothing happens in the screen.