Skip to content

Commit 757f181

Browse files
committed
fix(ionTab): make sure all tab-nav attributes are re-interpolated on change
Fixes #955. Closes #1071.
1 parent 5c300dd commit 757f181

File tree

2 files changed

+52
-24
lines changed

2 files changed

+52
-24
lines changed

Diff for: js/ext/angular/src/directive/ionicTabBar.js

+22-16
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ angular.module('ionic.ui.tabs', ['ionic.service.view'])
214214
controller: 'ionicTabs',
215215
compile: function(element, attr) {
216216
element.addClass('view');
217-
//We cannot use regular transclude here because it breaks element.data()
217+
//We cannot use regular transclude here because it breaks element.data()
218218
//inheritance on compile
219219
var innerElement = angular.element('<div class="tabs"></div>');
220220
innerElement.append(element.contents());
@@ -318,19 +318,36 @@ function($rootScope, $animate, $ionicBind, $compile, $ionicViewService, $state,
318318
controller: 'ionicTab',
319319
scope: true,
320320
compile: function(element, attr) {
321-
var navView = element[0].querySelector('ion-nav-view') ||
321+
var navView = element[0].querySelector('ion-nav-view') ||
322322
element[0].querySelector('data-ion-nav-view');
323323
var navViewName = navView && navView.getAttribute('name');
324324

325+
326+
//We create the tabNavElement in the compile phase so that the
327+
//attributes we pass down won't be interpolated yet - we want
328+
//to pass down the 'raw' versions of the attributes
329+
var tabNavElement = angular.element(
330+
'<ion-tab-nav' +
331+
attrStr('ng-click', attr.ngClick) +
332+
attrStr('title', attr.title) +
333+
attrStr('icon', attr.icon) +
334+
attrStr('icon-on', attr.iconOn) +
335+
attrStr('icon-off', attr.iconOff) +
336+
attrStr('badge', attr.badge) +
337+
attrStr('badge-style', attr.badgeStyle) +
338+
'></ion-tab-nav>'
339+
);
340+
325341
//Remove the contents of the element so we can compile them later, if tab is selected
326342
//We don't use regular transclusion because it breaks element inheritance
327343
var tabContent = angular.element('<div class="pane">')
328344
.append( element.contents().remove() );
329345

330346
return function link($scope, $element, $attr, ctrls) {
331-
var childScope, childElement, tabNavElement;
332-
tabsCtrl = ctrls[0],
333-
tabCtrl = ctrls[1];
347+
var childScope;
348+
var childElement;
349+
var tabsCtrl = ctrls[0];
350+
var tabCtrl = ctrls[1];
334351

335352
$ionicBind($scope, $attr, {
336353
animate: '=',
@@ -362,17 +379,6 @@ function($rootScope, $animate, $ionicBind, $compile, $ionicViewService, $state,
362379
}
363380
}
364381

365-
tabNavElement = angular.element(
366-
'<ion-tab-nav' +
367-
attrStr('ng-click', attr.ngClick) +
368-
attrStr('title', attr.title) +
369-
attrStr('icon', attr.icon) +
370-
attrStr('icon-on', attr.iconOn) +
371-
attrStr('icon-off', attr.iconOff) +
372-
attrStr('badge', attr.badge) +
373-
attrStr('badge-style', attr.badgeStyle) +
374-
'></ion-tab-nav>'
375-
);
376382
tabNavElement.data('$ionTabsController', tabsCtrl);
377383
tabNavElement.data('$ionTabController', tabCtrl);
378384
tabsCtrl.$tabsElement.append($compile(tabNavElement)($scope));

Diff for: js/ext/angular/test/directive/ionicTabBar.unit.js

+30-8
Original file line numberDiff line numberDiff line change
@@ -382,23 +382,45 @@ describe('tabs', function() {
382382
}));
383383

384384
it('should add itself to tabsCtrl and remove on $destroy', function() {
385-
var el = setup();
385+
setup();
386386
var tab = tabsCtrl.tabs[0];
387387
tab.$destroy();
388388
expect(tabsCtrl.remove).toHaveBeenCalledWith(tab);
389389
});
390390

391391
it('should compile a <ion-tab-nav> with all of the relevant attrs', function() {
392-
setup('title=1 icon-on=2 icon-off=3 badge=4 badge-style=5 ng-click=6');
392+
setup('title="{{a}}" icon-on="{{b}}" icon-off="{{c}}" badge="d" badge-style="{{e}}" ng-click="click"');
393+
angular.extend(tabEl.scope(), {
394+
a: 'title',
395+
b: 'on',
396+
c: 'off',
397+
d: 6,
398+
e: 'badger'
399+
});
400+
tabEl.scope().$apply();
393401
var navItem = angular.element(tabsEl[0].querySelector('.tab-item'));
394402
//Use .scope for title because we remove title attr
395403
//(for dom-tooltip not to appear)
396-
expect(navItem.scope().title).toEqual('1');
397-
expect(navItem.attr('icon-on')).toEqual('2');
398-
expect(navItem.attr('icon-off')).toEqual('3');
399-
expect(navItem.attr('badge')).toEqual('4');
400-
expect(navItem.attr('badge-style')).toEqual('5');
401-
expect(navItem.attr('ng-click')).toEqual('6');
404+
expect(navItem.isolateScope().title).toEqual('title');
405+
expect(navItem.isolateScope().iconOn).toEqual('on');
406+
expect(navItem.isolateScope().iconOff).toEqual('off');
407+
expect(navItem.isolateScope().badge).toEqual(6);
408+
expect(navItem.isolateScope().badgeStyle).toEqual('badger');
409+
expect(navItem.attr('ng-click')).toEqual('click');
410+
411+
angular.extend(tabEl.scope(), {
412+
a: 'title2',
413+
b: 'on2',
414+
c: 'off2',
415+
d: 7,
416+
e: 'badger2'
417+
});
418+
tabEl.scope().$apply();
419+
expect(navItem.isolateScope().title).toEqual('title2');
420+
expect(navItem.isolateScope().iconOn).toEqual('on2');
421+
expect(navItem.isolateScope().iconOff).toEqual('off2');
422+
expect(navItem.isolateScope().badge).toEqual(7);
423+
expect(navItem.isolateScope().badgeStyle).toEqual('badger2');
402424

403425
expect(navItem.parent()[0]).toBe(tabsCtrl.$tabsElement[0]);
404426
});

0 commit comments

Comments
 (0)