Skip to content

Commit ca41591

Browse files
author
Nedyalko Nikolov
committed
Added title and iconSource properties to TabViewDirective.
1 parent 4242572 commit ca41591

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

nativescript-angular/directives/tab-view.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ export class TabViewDirective {
3838
}
3939

4040
@Directive({
41-
selector: '[tabItem]'
41+
selector: '[tabItem]',
42+
inputs: ['title', 'iconSource']
4243
})
4344
export class TabViewItemDirective {
4445
private item: TabViewItem;
46+
private _title: string;
47+
private _iconSource: string;
4548

4649
constructor(
4750
private owner: TabViewDirective,
@@ -52,11 +55,34 @@ export class TabViewItemDirective {
5255

5356
@Input('tabItem') config: any;
5457

58+
set title(value: string) {
59+
if (this._title !== value) {
60+
this._title = value;
61+
this.ensureItem();
62+
this.item.title = this._title;
63+
}
64+
}
65+
66+
set iconSource(value: string) {
67+
if (this._iconSource !== value) {
68+
this._iconSource = value;
69+
this.ensureItem();
70+
this.item.iconSource = this._iconSource;
71+
}
72+
}
73+
74+
private ensureItem() {
75+
if (!this.item) {
76+
this.item = new TabViewItem();
77+
}
78+
}
79+
5580
ngOnInit() {
56-
this.item = new TabViewItem();
57-
this.item.title = this.config.title;
58-
59-
this.item.iconSource = this.config.iconSource;
81+
this.ensureItem();
82+
if (this.config) {
83+
this.item.title = this._title || this.config.title;
84+
this.item.iconSource = this._iconSource || this.config.iconSource;
85+
}
6086

6187
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
6288
//Filter out text nodes, etc
@@ -70,4 +96,4 @@ export class TabViewItemDirective {
7096
this.owner.tabView.items = newItems;
7197
}
7298
}
73-
}
99+
}

ng-sample/app/examples/tab-view/tab-view-test.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
<TabView selectedIndex="1" selectedColor="#FF0000">
2-
<StackLayout *tabItem="{title: 'Profile', iconSource: '~/icon.png'}" >
3-
<Label text="First tab item"></Label>
4-
</StackLayout>
1+
<TabView tabsBackgroundColor="#31bcff" #element [(ngModel)]="selectedIndex">
2+
<template tabItem title="{{selectedIndex === 0 ? 'Profile' : 'Test'}}">
3+
<StackLayout>
4+
<Label text="First tab item"></Label>
5+
</StackLayout>
6+
</template>
57
<StackLayout *tabItem="{title: 'Stats'}">
68
<Label text="Second tab item"></Label>
79
</StackLayout>

0 commit comments

Comments
 (0)