I am working on a web application and I'm using Angular for frontend and .Net for backend and I am quite new with both technologies. I have a database stored in SQL Server, I am taking the data using C# classes and I am passing it to the frontend using some controllers. I have an api.server.ts file which calls the functions from the controllers and these functions I use for all the components in my app. I have a component in which I am taking an array of products(all the products from the database) and show them in html (using ngfor), along with a button for each product. What I want to do it's when I press the button to redirect me to another component(which is a hole new page) and show me details about that particular product.
This is where I am using the function from the controller in frontend (I don't think it's useful to show the function because it works fine):
getProducts() {
return this.http.get(this.baseUrl + '/Product/GetAll', { headers: this.header });
}
This is the html part where I am displaying the products. The button 'Vezi produs' is redirecting me to the other component where I wanna see the product info for one particular product. I tried to use interpolation to take the product Id and return it in the api.service.ts(to set from the first components the value for product variable from api.service.ts) and from there I wanted to display it in the other component (using this.api.product), but it seems like I can't use interpolation.
<div *ngFor="let product of products;">
<div class="card" style="width: 15rem; height: 25rem; position:relative; margin-left:40px;">
<img src={{product.picture}} class="card-img-top" alt={{product.name}} style="width:15rem; height:13rem;">
<div class="card-body">
<h5 class="card-title"><b>{{product.name}}</b></h5>
<p class="card-text">{{product.description}}.</p>
<table>
<tr>
<td>
<a href="#" class="btn btn-primary" id="veziprodus" (onclick)="getProduct({{product.Id}});" [routerLinkActive]="['link-active']" [routerLink]='["/view-product"]'>Vezi produs</a>
</td>
<td>
<p style="position:absolute; bottom:10px; right:10px;">
<b> {{product.price}} lei </b>
</p>
</td>
</tr>
</table>
</div>
</div>
</div>
Also, I am having trouble with "siblings" components as well. I don't really know if my thinking was good and if I really can set the api.product value from the first component and then use the same variable to show it in the second component.