Code Ionic4
Code Ionic4
@Component({
selector: 'app-category-products',
templateUrl: './category-products.page.html',
styleUrls: ['./category-products.page.scss'],
})
export class CategoryProductsPage implements OnInit {
clickedCommerce: any;
categories: any[] = [];
commerceId!: number;
constructor(
private route: ActivatedRoute,
private categoryService: CategoryService,
private clickedElementService: ClickedElementService, // Inject
ClickedElementService
private router: Router
) {}
ngOnInit() {
this.route.params.subscribe((params) => {
// Extract commerceId from route parameters
const commerceId = params['id'];
// Retrieve clickedCommerce from ClickedElementService
this.clickedElementService.getClickedCommerce().subscribe((clickedCommerce)
=> {
this.clickedCommerce = clickedCommerce;
console.log('clickedCommerce called in CategoryProductsPage : ',
this.clickedCommerce);
});
// Retrieve categories belonging to the current commerce
this.getCategoriesByCommerceId(commerceId);
this.commerceId = commerceId;
});
}
goToCreateCategoryModal(categoryId: number) {
const clickedCategory = this.categories.find(
(category) => category.id === categoryId
);
this.router.navigate(['/create-category-modal', categoryId, {commerceId:
this.commerceId}]);
}
}