@@ -215,20 +215,22 @@ function($ionicViewService, $rootScope, $animate, $compile, $parse) {
215
215
216
216
return {
217
217
restrict : 'E' ,
218
- replace : true ,
219
- transclude : true ,
220
218
controller : '$ionicNavBar' ,
221
- template :
222
- '<header class="bar bar-header nav-bar{{navBarClass()}}">' +
223
- '<div class="buttons left-buttons"> ' +
224
- '</div>' +
225
- '<h1 ng-bind-html="title" class="title"></h1>' +
226
- '<div class="buttons right-buttons"> ' +
227
- '</div>' +
228
- '</header>' ,
229
- compile : function ( tElement , tAttrs , transclude ) {
219
+ scope : true ,
220
+ compile : function ( tElement , tAttrs ) {
221
+ //We cannot transclude here because it breaks element.data() inheritance on compile
222
+ tElement
223
+ . addClass ( 'bar bar-header nav-bar' )
224
+ . append (
225
+ '<div class="buttons left-buttons"> ' +
226
+ '</div>' +
227
+ '<h1 ng-bind-html="title" class="title"></h1>' +
228
+ '<div class="buttons right-buttons"> ' +
229
+ '</div>'
230
+ ) ;
230
231
231
- return function link ( $scope , $element , $attr , navBarCtrl ) {
232
+ return { pre : prelink } ;
233
+ function prelink ( $scope , $element , $attr , navBarCtrl ) {
232
234
navBarCtrl . _headerBarView = new ionic . views . HeaderBar ( {
233
235
el : $element [ 0 ] ,
234
236
alignTitle : $attr . alignTitle || 'center'
@@ -237,23 +239,23 @@ function($ionicViewService, $rootScope, $animate, $compile, $parse) {
237
239
$parse ( $attr . controllerBind || '$ionicNavBarController' )
238
240
. assign ( $scope , navBarCtrl ) ;
239
241
240
- //Put transcluded content (usually a back button) before the rest
241
- transclude ( $scope , function ( clone ) {
242
- $element . prepend ( clone ) ;
243
- } ) ;
244
-
245
242
//defaults
246
243
$scope . backButtonShown = false ;
247
244
$scope . shouldAnimate = true ;
248
245
$scope . isReverse = false ;
249
246
$scope . isInvisible = true ;
247
+ $scope . $parent . $hasHeader = true ;
250
248
251
- $scope . navBarClass = function ( ) {
249
+ $scope . $watch ( function ( ) {
252
250
return ( $scope . isReverse ? ' reverse' : '' ) +
253
251
( $scope . isInvisible ? ' invisible' : '' ) +
254
252
( ! $scope . shouldAnimate ? ' no-animation' : '' ) ;
255
- } ;
256
- } ;
253
+ } , function ( className , oldClassName ) {
254
+ $element . removeClass ( oldClassName ) ;
255
+ $element . addClass ( className ) ;
256
+ } ) ;
257
+
258
+ }
257
259
}
258
260
} ;
259
261
} ] )
@@ -311,32 +313,30 @@ function($ionicViewService, $rootScope, $animate, $compile, $parse) {
311
313
return {
312
314
restrict : 'E' ,
313
315
require : '^ionNavBar' ,
314
- replace : true ,
315
- transclude : true ,
316
- template :
317
- '<button class="button back-button" ng-transclude>' +
318
- '</button>' ,
319
- link : function ( $scope , $element , $attr , navBarCtrl ) {
320
- $scope . $navBack = navBarCtrl . back ;
321
- if ( ! $attr . ngClick ) {
322
- $ionicNgClick ( $scope , $element , '$navBack($event)' ) ;
323
- }
324
-
325
- //If the current viewstate does not allow a back button,
326
- //always hide it.
327
- var deregisterListener = $scope . $parent . $on (
328
- '$viewHistory.historyChange' ,
329
- function ( e , data ) {
330
- $scope . hasBackButton = ! ! data . showBack ;
316
+ compile : function ( tElement , tAttrs ) {
317
+ tElement . addClass ( 'button back-button' ) ;
318
+ return function ( $scope , $element , $attr , navBarCtrl ) {
319
+ $scope . $navBack = navBarCtrl . back ;
320
+ if ( ! $attr . ngClick ) {
321
+ $ionicNgClick ( $scope , $element , '$navBack($event)' ) ;
331
322
}
332
- ) ;
333
- $scope . $on ( '$destroy' , deregisterListener ) ;
334
323
335
- //Make sure both that a backButton is allowed in the first place,
336
- //and that it is shown by the current view.
337
- $scope . $watch ( '!!(backButtonShown && hasBackButton)' , function ( val ) {
338
- $element . toggleClass ( 'hide' , ! val ) ;
339
- } ) ;
324
+ //If the current viewstate does not allow a back button,
325
+ //always hide it.
326
+ var deregisterListener = $scope . $parent . $on (
327
+ '$viewHistory.historyChange' ,
328
+ function ( e , data ) {
329
+ $scope . hasBackButton = ! ! data . showBack ;
330
+ }
331
+ ) ;
332
+ $scope . $on ( '$destroy' , deregisterListener ) ;
333
+
334
+ //Make sure both that a backButton is allowed in the first place,
335
+ //and that it is shown by the current view.
336
+ $scope . $watch ( '!!(backButtonShown && hasBackButton)' , function ( val ) {
337
+ $element . toggleClass ( 'hide' , ! val ) ;
338
+ } ) ;
339
+ } ;
340
340
}
341
341
} ;
342
342
} ] )
@@ -379,9 +379,8 @@ function($ionicViewService, $rootScope, $animate, $compile, $parse) {
379
379
. directive ( 'ionNavButtons' , [ '$compile' , '$animate' , function ( $compile , $animate ) {
380
380
return {
381
381
require : '^ionNavBar' ,
382
- transclude : true ,
383
382
restrict : 'E' ,
384
- compile : function ( $element , $attrs , transclude ) {
383
+ compile : function ( $element , $attrs ) {
385
384
return function ( $scope , $element , $attrs , navBarCtrl ) {
386
385
var navElement = $attrs . side === 'right' ?
387
386
navBarCtrl . rightButtonsElement :
@@ -391,13 +390,13 @@ function($ionicViewService, $rootScope, $animate, $compile, $parse) {
391
390
//so we can remove them all when this element dies -
392
391
//even if the buttons have changed through an ng-repeat or the like,
393
392
//we just remove their div parent and they are gone.
394
- var clone = angular . element ( '<div>' ) . append ( transclude ( $scope ) ) ;
395
- $animate . enter ( clone , navElement ) ;
393
+ var buttons = angular . element ( '<div>' ) . append ( $element . contents ( ) . remove ( ) ) ;
394
+ $animate . enter ( buttons , navElement ) ;
396
395
397
396
//When our ion-nav-buttons container is destroyed,
398
397
//destroy everything in the navbar
399
398
$scope . $on ( '$destroy' , function ( ) {
400
- $animate . leave ( clone ) ;
399
+ $animate . leave ( buttons ) ;
401
400
} ) ;
402
401
403
402
// The original element is just a completely empty <ion-nav-buttons> element.
0 commit comments