@@ -144,7 +144,8 @@ function($scope, $ionicViewService, $rootScope, $element) {
144
144
} ] )
145
145
146
146
// Generic controller directive
147
- . directive ( 'ionTab' , [ '$rootScope' , '$animate' , '$ionicBind' , '$compile' , '$ionicViewService' , function ( $rootScope , $animate , $ionicBind , $compile , $ionicViewService ) {
147
+ . directive ( 'ionTab' , [ '$rootScope' , '$animate' , '$ionicBind' , '$compile' , '$ionicViewService' ,
148
+ function ( $rootScope , $animate , $ionicBind , $compile , $ionicViewService ) {
148
149
149
150
//Returns ' key="value"' if value exists
150
151
function attrStr ( k , v ) {
@@ -154,10 +155,17 @@ function($scope, $ionicViewService, $rootScope, $element) {
154
155
restrict : 'E' ,
155
156
require : [ '^ionTabs' , 'ionTab' ] ,
156
157
replace : true ,
157
- transclude : 'element' ,
158
158
controller : '$ionicTab' ,
159
159
scope : true ,
160
- compile : function ( element , attr , transclude ) {
160
+ compile : function ( element , attr ) {
161
+ //Do we have a navView?
162
+ var navView = element [ 0 ] . querySelector ( 'ion-nav-view' ) ||
163
+ element [ 0 ] . querySelector ( 'data-ion-nav-view' ) ;
164
+ var navViewName = navView && navView . getAttribute ( 'name' ) ;
165
+
166
+ //Remove the contents of the element so we can compile them later, if tab is selected
167
+ var tabContent = angular . element ( '<div class="pane">' )
168
+ . append ( element . contents ( ) . remove ( ) ) ;
161
169
return function link ( $scope , $element , $attr , ctrls ) {
162
170
var childScope , childElement , tabNavElement ;
163
171
tabsCtrl = ctrls [ 0 ] ,
@@ -174,6 +182,19 @@ function($scope, $ionicViewService, $rootScope, $element) {
174
182
href : '@' ,
175
183
} ) ;
176
184
185
+ tabsCtrl . add ( $scope ) ;
186
+ $scope . $on ( '$destroy' , function ( ) {
187
+ tabsCtrl . remove ( $scope ) ;
188
+ tabNavElement . isolateScope ( ) . $destroy ( ) ;
189
+ tabNavElement . remove ( ) ;
190
+ } ) ;
191
+
192
+ if ( navViewName ) {
193
+ $scope . navViewName = navViewName ;
194
+ $scope . $on ( '$stateChangeSuccess' , selectTabIfMatchesState ) ;
195
+ selectTabIfMatchesState ( ) ;
196
+ }
197
+
177
198
tabNavElement = angular . element (
178
199
'<ion-tab-nav' +
179
200
attrStr ( 'title' , attr . title ) +
@@ -188,13 +209,6 @@ function($scope, $ionicViewService, $rootScope, $element) {
188
209
tabNavElement . data ( '$ionTabController' , tabCtrl ) ;
189
210
tabsCtrl . $tabsElement . append ( $compile ( tabNavElement ) ( $scope ) ) ;
190
211
191
- tabsCtrl . add ( $scope ) ;
192
- $scope . $on ( '$destroy' , function ( ) {
193
- tabsCtrl . remove ( $scope ) ;
194
- tabNavElement . isolateScope ( ) . $destroy ( ) ;
195
- tabNavElement . remove ( ) ;
196
- } ) ;
197
-
198
212
$scope . $watch ( '$tabSelected' , function ( value ) {
199
213
if ( ! value ) {
200
214
$scope . $broadcast ( 'tab.hidden' , $scope ) ;
@@ -205,26 +219,13 @@ function($scope, $ionicViewService, $rootScope, $element) {
205
219
childElement = null ;
206
220
if ( value ) {
207
221
childScope = $scope . $new ( ) ;
208
- transclude ( childScope , function ( clone ) {
209
- //remove title attr to stop hover annoyance!
210
- clone [ 0 ] . removeAttribute ( 'title' ) ;
211
- $animate . enter ( clone , tabsCtrl . $element ) ;
212
- clone . addClass ( 'pane' ) ;
213
- childElement = clone ;
214
- } ) ;
222
+ childElement = tabContent . clone ( ) ;
223
+ $animate . enter ( childElement , tabsCtrl . $element ) ;
224
+ $compile ( childElement ) ( childScope ) ;
215
225
$scope . $broadcast ( 'tab.shown' , $scope ) ;
216
226
}
217
227
} ) ;
218
228
219
- transclude ( $scope , function ( clone ) {
220
- var navView = clone [ 0 ] . querySelector ( 'ion-nav-view' ) ;
221
- if ( navView ) {
222
- $scope . navViewName = navView . getAttribute ( 'name' ) ;
223
- selectTabIfMatchesState ( ) ;
224
- $scope . $on ( '$stateChangeSuccess' , selectTabIfMatchesState ) ;
225
- }
226
- } ) ;
227
-
228
229
function selectTabIfMatchesState ( ) {
229
230
// this tab's ui-view is the current one, go to it!
230
231
if ( $ionicViewService . isCurrentStateNavView ( $scope . navViewName ) ) {
0 commit comments