Skip to content
This repository was archived by the owner on Sep 24, 2020. It is now read-only.

Commit b20af24

Browse files
committed
Add TabView directives.
1 parent e41ed22 commit b20af24

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import {Type} from 'angular2/src/facade/lang';
22
import {ListItemTemplate, ListViewDirective} from './list-view';
3-
import { TextValueAccessor } from '../text-value-accessor';
3+
import {TextValueAccessor} from '../text-value-accessor';
4+
import {TabViewDirective, TabViewItemDirective} from './tab-view';
45

5-
export const NS_DIRECTIVES: Type[] = [ListItemTemplate, ListViewDirective, TextValueAccessor];
6+
export const NS_DIRECTIVES: Type[] = [
7+
ListItemTemplate,
8+
ListViewDirective,
9+
10+
TabViewDirective,
11+
TabViewItemDirective,
12+
13+
TextValueAccessor
14+
];
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import {ElementRef, Directive, Input, TemplateRef, ViewContainerRef} from "angular2/core";
2+
import {TabView, TabViewItem} from "ui/tab-view";
3+
import {isView} from "../view-util";
4+
5+
@Directive({
6+
selector: 'TabView'
7+
})
8+
export class TabViewDirective {
9+
public tabView: TabView;
10+
11+
constructor(private element: ElementRef) {
12+
this.tabView = element.nativeElement;
13+
}
14+
}
15+
16+
@Directive({
17+
selector: '[tabItem]'
18+
})
19+
export class TabViewItemDirective {
20+
private item: TabViewItem;
21+
22+
constructor(
23+
private owner: TabViewDirective,
24+
private templateRef: TemplateRef,
25+
private viewContainer: ViewContainerRef
26+
) {
27+
}
28+
29+
@Input('tabItem') config: any;
30+
31+
ngOnInit() {
32+
this.item = new TabViewItem();
33+
this.item.title = this.config.title;
34+
35+
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
36+
//Filter out text nodes, etc
37+
const realViews = viewRef.rootNodes.filter((node) =>
38+
node.nodeName && node.nodeName !== '#text')
39+
40+
if (realViews.length > 0) {
41+
this.item.view = realViews[0];
42+
43+
const newItems = (this.owner.tabView.items || []).concat([this.item]);
44+
this.owner.tabView.items = newItems;
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)