Skip to content
Snippets Groups Projects
Commit 2497e56e authored by KPOTY Kpotivi's avatar KPOTY Kpotivi
Browse files

rebasing on feature/add-routings

parent 9a91dc6a
No related branches found
No related tags found
No related merge requests found
<p>products works!</p> <p [ngIf]="errorMessage" [ngIfElse]="ShowProducts">
{{ errorMessage }}
</p>
<<ng-template #ShowProducts>
<div *ngFor="let product of productsList">
<p>{{ product.id }}</p>
<p>{{ product.title }}</p>
<p>{{ product.price }}</p>
<p>{{ product.quantity }}</p>
<p>{{ product.photo }}</p>
</div>
</ng-template>
import { Component } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ProductDTO } from 'src/api-client';
import { ProductService } from 'src/app/services/product.service';
@Component({ @Component({
selector: 'app-products', selector: 'app-products',
templateUrl: './products.component.html', templateUrl: './products.component.html',
styleUrls: ['./products.component.scss'] styleUrls: ['./products.component.scss'],
}) })
export class ProductsComponent { export class ProductsComponent implements OnInit {
productsList!: ProductDTO[];
errorMessage!: string;
constructor(private productsService: ProductService) {}
ngOnInit(): void {
this.initProductsList();
}
/* Init the products list by fetching products from the databse */
private initProductsList(): void {
this.productsService.getProducts().subscribe({
next: (data: ProductDTO[]) => {
this.productsList = [...data];
},
error: () => {
this.errorMessage = 'Could not fetch products from database';
},
});
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment