Angular
Archiviert 2 years ago
G
Bulbula
can someone help me,im trying to write a code that redirects the user to the page with a chosen item when they click buy
the code
(export class ProductsComponent {
product: any;
buyItem(arg0: any) {
throw new Error('Method not implemented.');
}
public productList: any[] = [];
public filteredList: any[] = [];
public category!: any;
public minPrice!:any;
public maxPrice!:any;
constructor(private service: HttpService, public route: ActivatedRoute, private router: Router) {
this.service.getAllProducts().subscribe( data => {
this.productList = data;
this.filteredList = this.productList.filter(product => product.category == this.category.info);
if (this.filteredList.length < 1) {
this.filteredList = this.productList
}
})
this.route.queryParams.subscribe(item => this.category = item)
}
filterByPrice() {
if (this.maxPrice) {
this.filteredList = this.filteredList.filter(product => product.price >= this.minPrice && product.price <= this.maxPrice);
} else {
this.filteredList = this.filteredList.filter(product => product.price >= this.minPrice);
}
} )

