Currently i trying to do a SPA using Angular 9. I made a module called products with this route localhost:4200/products and for find a specified product i using this route http://localhost:4200/products/(number_id_product)
I thought to implement this component for each time i need to see a product. My problem is when i go to another product from the current product page using a link with [routerlink], (http://localhost:4200/products/1 to http://localhost:4200/products/2 )the url changes but the content page doesnt changes and keep the same info of the last product.
I dont know what is going on with the [routerlink] redirection
my code .ts
import { Component, OnInit } from '@angular/core';
import { Product } from 'src/app/shared/models/product';
import { ActivatedRoute } from '@angular/router';
import { ProductsService } from 'src/app/shared/services/products.service';
@Component({
selector: 'ec-product-description',
templateUrl: './product-description.component.html',
styleUrls: ['./product-description.component.css']
})
export class ProductDescriptionComponent implements OnInit {
id: string;
product: Product
constructor(private route: ActivatedRoute, private service: ProductsService) { }
ngOnInit(): void {
this.id= this.route.snapshot.paramMap.get('id')
//get products/id
this.service.getProduct(this.id)
.subscribe(prod=>{
console.log(`Prod ↓ `)
console.log(prod)
this.product=prod
})
}
}
my code html
<div class="container-product">
<h1>{{product.title}}</h1>
<img mat-card-image [src]="product.thumbImage">
<span class="product-descrp">{{product.description}}</span>
<span [routerLink]="['','products','another_id_product']">See another product!</span>
</div>