diff --git a/src/app/components/tabmenu/tabmenu.ts b/src/app/components/tabmenu/tabmenu.ts index 12a7a9cf236..b040b499251 100644 --- a/src/app/components/tabmenu/tabmenu.ts +++ b/src/app/components/tabmenu/tabmenu.ts @@ -1,7 +1,8 @@ -import {NgModule,Component,ElementRef,Input,Output} from '@angular/core'; +import {NgModule,Component,Input,ContentChildren,QueryList,AfterContentInit,TemplateRef} from '@angular/core'; import {CommonModule} from '@angular/common'; import {DomHandler} from '../dom/domhandler'; import {MenuItem} from '../common/menuitem'; +import {PrimeTemplate} from '../common/shared'; import {RouterModule} from '@angular/router'; @Component({ @@ -9,19 +10,25 @@ import {RouterModule} from '@angular/router'; template: `
By defaulttem item that matches the active route is highlighted, alternatively activeItem property can be used choose the initial active item.
+By default item that matches the active route is highlighted, alternatively activeItem property can be used choose the initial active item.
<p-tabMenu [model]="items" [activeItem]="items[0]"></p-tabMenu>
@@ -79,6 +95,18 @@ ActiveItem
}
}
+
+
+ Menuitem content supports templating via the "item" template which gets the menuitem instance and the index.
+
+
+<p-tabMenu [model]="items">
+ <ng-template pTemplate="item" let-item let-i="index">
+ //item content
+ </ng-template>
+</p-tabMenu>
+
-<p-tabMenu [model]="items"></p-tabMenu>
+<h3 class="first">Default</h3>
+<p-tabMenu [model]="items1" [activeItem]="items1[0]"></p-tabMenu>
+
+<h3>Templating</h3>
+<p-tabMenu [model]="items2" [activeItem]="activeItem">
+ <ng-template pTemplate="item" let-item let-i="index">
+ <div style="position: relative; text-align: center; min-width: 10em">
+ <div class="ui-menuitem-icon" [ngClass]="item.icon" *ngIf="item.icon" style="font-size: 2em"></div>
+ <div class="ui-menuitem-text">
+ {{item.label}}
+ </div>
+ <a tabindex="0" class="ui-menuitem-icon" (click)="closeItem($event, i)" style="position: absolute; right: -1em; top: -.5em; padding: 0" *ngIf="i !== 0">
+ <span class="pi pi-times"></span>
+ </a>
+ </div>
+ </ng-template>
+</p-tabMenu>
@@ -179,17 +223,37 @@
export class TabMenuDemo {
- items: MenuItem[];
+ items1: MenuItem[];
+
+ items2: MenuItem[];
+
+ activeItem: MenuItem;
ngOnInit() {
- this.items = [
+ this.items1 = [
+ {label: 'Stats', icon: 'fa fa-fw fa-bar-chart'},
+ {label: 'Calendar', icon: 'fa fa-fw fa-calendar'},
+ {label: 'Documentation', icon: 'fa fa-fw fa-book'},
+ {label: 'Support', icon: 'fa fa-fw fa-support'},
+ {label: 'Social', icon: 'fa fa-fw fa-twitter'}
+ ];
+
+ this.items2 = [
{label: 'Stats', icon: 'fa fa-fw fa-bar-chart'},
{label: 'Calendar', icon: 'fa fa-fw fa-calendar'},
{label: 'Documentation', icon: 'fa fa-fw fa-book'},
{label: 'Support', icon: 'fa fa-fw fa-support'},
{label: 'Social', icon: 'fa fa-fw fa-twitter'}
];
+
+ this.activeItem = this.items2[0];
}
+
+ closeItem(event, index) {
+ this.items2 = this.items2.filter((item, i) => i !== index);
+ event.preventDefault();
+ }
+
}
diff --git a/src/app/showcase/components/tabmenu/tabmenudemo.ts b/src/app/showcase/components/tabmenu/tabmenudemo.ts
index c829f442ff6..3c6230a1ab2 100644
--- a/src/app/showcase/components/tabmenu/tabmenudemo.ts
+++ b/src/app/showcase/components/tabmenu/tabmenudemo.ts
@@ -6,15 +6,34 @@ import {MenuItem} from '../../../components/common/api';
})
export class TabMenuDemo {
- items: MenuItem[];
+ items1: MenuItem[];
+
+ items2: MenuItem[];
+
+ activeItem: MenuItem;
ngOnInit() {
- this.items = [
+ this.items1 = [
+ {label: 'Stats', icon: 'fa fa-fw fa-bar-chart'},
+ {label: 'Calendar', icon: 'fa fa-fw fa-calendar'},
+ {label: 'Documentation', icon: 'fa fa-fw fa-book'},
+ {label: 'Support', icon: 'fa fa-fw fa-support'},
+ {label: 'Social', icon: 'fa fa-fw fa-twitter'}
+ ];
+
+ this.items2 = [
{label: 'Stats', icon: 'fa fa-fw fa-bar-chart'},
{label: 'Calendar', icon: 'fa fa-fw fa-calendar'},
{label: 'Documentation', icon: 'fa fa-fw fa-book'},
{label: 'Support', icon: 'fa fa-fw fa-support'},
{label: 'Social', icon: 'fa fa-fw fa-twitter'}
];
+
+ this.activeItem = this.items2[0];
+ }
+
+ closeItem(event, index) {
+ this.items2 = this.items2.filter((item, i) => i !== index);
+ event.preventDefault();
}
}
\ No newline at end of file