简体   繁体   English

如果网址更改,如何更改primeng下拉值/选项

[英]How to change primeng dropdown value/option if url changes

I am very new to Primeng and Angular, Can you help me with this please:我对 Primeng 和 Angular 很陌生,请你帮我解决这个问题:

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.如何使用 Angular 中的 Primeng下拉菜单更改 URL 中的参数:(例如, URL 中的 shop1 到 shop2) http://localhost:4200/#/shops/shop1/dashboard如果我更改 URL,反之亦然,所以它必须更改下拉的值也是如此。

 <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)函数在组件中返回{shopId: 'shop2', name: 'Shop 2'}如何从事件中获取 shopId?:

   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}); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM