I am very new to Primeng and Angular, Can you help me with this please:
How to change my param in URL using Primeng drop-down in Angular: (ex. shop1 in URL to shop2) http://localhost:4200/#/shops/shop1/dashboard and vice versa if I change URL so it must change the value of drop-down as well.
<p-dropdown [options]="clientShops" [(ngModel)]="selectedShop" optionLabel="name" (onChange)="onChange($event)"></p-dropdown>
My OnChange($event) function returns {shopId: 'shop2', name: 'Shop 2'} in component How to get shopId from event?:
onChange(event: any) {
// How to get shopId from event?
let shopId = "";
this.router.navigate([`/shops/${shopId}/dashboard`]);
console.log('event :' + event);
console.log(event.value);
}
// import
import { ActivatedRoute, Router } from "@angular/router";
// in your constructor
constructor(private route: ActivatedRoute,private router: Router) {}
// on changing the dropdown value
onDropdownChange(event: any) {
this.router.navigate(['../../', + event.shopId + '/dashboard'],{relativeTo: this.route});
}