2017-09-16 5 views
-1

Où puis-je déclarer activeIndex et comment utiliser cette variable?Comment définir l'onglet actif dans l'onglet PrimeNGMenu?

je fichier html:

<p-tabMenu [model]="tabMenuItems"></p-tabMenu> 

et le fichier tapuscrit:

tabMenuItems: MenuItem[]; 
private stateId: number; 
private id: number; 
... 
ngOnInit() { 
    this.tabMenuItems = [ 
     {label: 'Bar1', icon: 'ui-icon-insert-chart', 
      command: (event: any) => { 
       this.router.navigate(['/#', 
      this.id],{ queryParams: {'stateId': this.stateId} }); } 
     }, 
     {label: 'Bar2', icon: 'ui-icon-date-range', 
      command: (event: any) => { 
       this.router.navigate(['/#', this.id],{ queryParams: {'stateId': this.stateId} }); } 
     }, 
     {label: 'Bar3', icon: 'ui-icon-book', 
      command: (event: any) => { 
       this.router.navigate(['/#', this.id], 
        { queryParams: {'stateId': this.stateId} }); } 
     }, 
     {label: 'Bar4', icon: 'ui-icon-help-outline', 
      command: (event: any) => { 
       this.router.navigate(['/#', this.id], 
        { queryParams: {'stateId': this.stateId} }); } 
     }, 
     {label: 'Bar5', icon: 'ui-icon-public', 
      command: (event: any) => { 
       this.router.navigate(['/#', this.id], 
        { queryParams: {'stateId': this.stateId} }); } 
     } 
    ]; 

Comment définir l'onglet actif, de sorte que chaque élément de menu activer l'onglet correspondant?

+0

ajouter [activeItem] = "activeItem" => activeItem est que vous l'objet sélectionné dans le composant – Chandru

Répondre

0

Documentation

Set [activeItem] propriété sur le tabMenu.

Exemple

ngOnInit() { 
    this.tabMenuItems = [ 
     {label: 'Bar1', icon: 'ui-icon-insert-chart', 
      command: (event: any) => { 
       this.router.navigate(['/#', 
      this.id],{ queryParams: {'stateId': this.stateId} }); } 
     }, 
     {label: 'Bar2', icon: 'ui-icon-date-range', 
      command: (event: any) => { 
       this.router.navigate(['/#', this.id],{ queryParams: {'stateId': this.stateId} }); } 
     }, 
     {label: 'Bar3', icon: 'ui-icon-book', 
      command: (event: any) => { 
       this.router.navigate(['/#', this.id], 
        { queryParams: {'stateId': this.stateId} }); } 
     }, 
     {label: 'Bar4', icon: 'ui-icon-help-outline', 
      command: (event: any) => { 
       this.router.navigate(['/#', this.id], 
        { queryParams: {'stateId': this.stateId} }); } 
     }, 
     {label: 'Bar5', icon: 'ui-icon-public', 
      command: (event: any) => { 
       this.router.navigate(['/#', this.id], 
        { queryParams: {'stateId': this.stateId} }); } 
     } 
    ]; 

    this.activeTab = this.tabMenuItems[1]; 
} 

En HTML

<p-tabMenu [model]="tabMenuItems" [activeItem]='activeTab'></p-tabMenu> 
+0

Merci! Il m'a aidé – anikkinho

+0

@ anikkinho si cela aide, vous pouvez accepter cela pour aider les autres à le trouver facilement –