@@ -14,6 +14,12 @@ import { InvisibleNode } from "../element-registry";
14
14
import { rendererLog } from "../trace" ;
15
15
import { isBlank } from "../lang-facade" ;
16
16
17
+ export interface TabViewItemDef {
18
+ title ?: string ;
19
+ iconSource ?: string ;
20
+ textTransform ?: TextTransform ;
21
+ }
22
+
17
23
@Directive ( {
18
24
selector : "TabView" , // tslint:disable-line:directive-selector
19
25
} )
@@ -52,9 +58,7 @@ export class TabViewDirective implements AfterViewInit {
52
58
} )
53
59
export class TabViewItemDirective implements OnInit {
54
60
private item : TabViewItem ;
55
- private _title : string ;
56
- private _iconSource : string ;
57
- private _textTransform : TextTransform ;
61
+ private _config : TabViewItemDef ;
58
62
59
63
constructor (
60
64
private owner : TabViewDirective ,
@@ -63,46 +67,46 @@ export class TabViewItemDirective implements OnInit {
63
67
) {
64
68
}
65
69
66
- @Input ( "tabItem" ) config : any ; // tslint:disable-line:no-input-rename
70
+ @Input ( "tabItem" )
71
+ set config ( config : TabViewItemDef ) {
72
+ if ( ! this . _config
73
+ || this . _config . iconSource !== config . iconSource
74
+ || this . _config . title !== config . title
75
+ || this . _config . textTransform !== config . textTransform ) {
76
+ this . _config = config ;
77
+ this . applyConfig ( ) ;
78
+ }
79
+ }
80
+
81
+ get config ( ) : TabViewItemDef { // tslint:disable-line:no-input-rename
82
+ return this . _config || { } ;
83
+ }
67
84
68
85
@Input ( )
69
- get title ( ) {
70
- return this . _title ;
86
+ set title ( title : string ) {
87
+ this . config = Object . assign ( this . config , { title } ) ;
71
88
}
72
89
73
- set title ( value : string ) {
74
- if ( this . _title !== value ) {
75
- this . _title = value ;
76
- this . ensureItem ( ) ;
77
- this . item . title = this . _title ;
78
- }
90
+ get title ( ) {
91
+ return this . config . title ;
79
92
}
80
93
81
94
@Input ( )
82
- get iconSource ( ) {
83
- return this . _iconSource ;
95
+ set iconSource ( iconSource : string ) {
96
+ this . config = Object . assign ( this . config , { iconSource } ) ;
84
97
}
85
98
86
- set iconSource ( value : string ) {
87
- if ( this . _iconSource !== value ) {
88
- this . _iconSource = value ;
89
- this . ensureItem ( ) ;
90
- this . item . iconSource = this . _iconSource ;
91
- }
99
+ get iconSource ( ) {
100
+ return this . config . iconSource ;
92
101
}
93
102
94
-
95
103
@Input ( )
96
- get textTransform ( ) {
97
- return this . _textTransform ;
104
+ set textTransform ( textTransform : TextTransform ) {
105
+ this . config = Object . assign ( this . config , { textTransform } ) ;
98
106
}
99
107
100
- set textTransform ( value : TextTransform ) {
101
- if ( this . _textTransform && this . _textTransform !== value ) {
102
- this . _textTransform = value ;
103
- this . ensureItem ( ) ;
104
- this . item . textTransform = this . _textTransform ;
105
- }
108
+ get textTransform ( ) {
109
+ return this . config . textTransform ;
106
110
}
107
111
108
112
private ensureItem ( ) {
@@ -111,19 +115,26 @@ export class TabViewItemDirective implements OnInit {
111
115
}
112
116
}
113
117
114
- ngOnInit ( ) {
118
+ private applyConfig ( ) {
115
119
this . ensureItem ( ) ;
116
- if ( this . config ) {
117
- this . item . title = this . _title || this . config . title ;
118
- this . item . iconSource = this . _iconSource || this . config . iconSource ;
119
-
120
- // TabViewItem textTransform has a default value for Android that kick in
121
- // only if no value (even a null value) is set.
122
- const textTransformValue = this . _textTransform || this . config . textTransform ;
123
- if ( textTransformValue ) {
124
- this . item . textTransform = textTransformValue ;
125
- }
120
+
121
+ if ( this . config . title ) {
122
+ this . item . title = this . config . title ;
123
+ }
124
+
125
+ if ( this . config . iconSource ) {
126
+ this . item . iconSource = this . config . iconSource ;
127
+ }
128
+
129
+ // TabViewItem textTransform has a default value for Android that kick in
130
+ // only if no value (even a null value) is set.
131
+ if ( this . config . textTransform ) {
132
+ this . item . textTransform = this . config . textTransform ;
126
133
}
134
+ }
135
+
136
+ ngOnInit ( ) {
137
+ this . applyConfig ( ) ;
127
138
128
139
const viewRef = this . viewContainer . createEmbeddedView ( this . templateRef ) ;
129
140
// Filter out text nodes and comments
0 commit comments