2017-09-16 7 views
-1

ここで私はactiveIndexを宣言し、この変数の使い方は?PrimeNG tabMenuでアクティブなタブを設定するにはどうすればよいですか?

I持って htmlファイル:

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

とtypescriptですファイル:私は、アクティブなタブを設定することができますので、各メニュー項目は、対応するタブをアクティブにする方法

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

+0

[activeItem] = "activeItem" => activeItemを追加ありがとう、あなたがコンポーネント – Chandru

答えて

0

Documentation

tabMenu[activeItem]プロパティを設定します。

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]; 
} 
HTML

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

で選択したオブジェクトこれは!それは助けてくれました – anikkinho

+0

@anikkinhoこれが役に立ったら、これを受け入れて他の人が簡単に見つけるのを助けることができます –

関連する問題