Skip to content

Commit 0ffb748

Browse files
committed
refactor(ionNavBackButton): make click handler use $ionicNgClick service
Closes #802
1 parent 90f360c commit 0ffb748

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

js/ext/angular/src/directive/ionicNavBar.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ function($ionicViewService, $rootScope, $animate, $compile, $parse) {
282282
* </ion-nav-bar>
283283
* ```
284284
*/
285-
.directive('ionNavBackButton', [function() {
285+
.directive('ionNavBackButton', ['$ionicNgClick', function($ionicNgClick) {
286286
return {
287287
restrict: 'E',
288288
require: '^ionNavBar',
@@ -292,8 +292,9 @@ function($ionicViewService, $rootScope, $animate, $compile, $parse) {
292292
'<button class="button back-button" ng-transclude>' +
293293
'</button>',
294294
link: function($scope, $element, $attr, navBarCtrl) {
295+
$scope.$navBack = navBarCtrl.back;
295296
if (!$attr.ngClick) {
296-
ionic.on('tap', navBarCtrl.back, $element[0]);
297+
$ionicNgClick($scope, $element, '$navBack($event)');
297298
}
298299

299300
//If the current viewstate does not allow a back button,

js/ext/angular/test/directive/ionicNavBackButton.unit.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
describe('ionNavBackButton directive', function() {
2-
beforeEach(module('ionic.ui.navBar'));
2+
beforeEach(module('ionic'));
33

44
function setup(attr, content) {
55
var el;
@@ -53,19 +53,19 @@ describe('ionNavBackButton directive', function() {
5353
expect(el.children().eq(0)[0].tagName.toLowerCase()).toBe('b');
5454
});
5555

56-
it('should add onTap if ngClick isnt defined', function() {
57-
spyOn(ionic, 'on');
56+
it('should $navBack on click by default', function() {
5857
var el = setup();
59-
expect(ionic.on).toHaveBeenCalledWith(
60-
'tap',
61-
el.controller('ionNavBar').back,
62-
el[0]
63-
);
58+
el.scope().$navBack = jasmine.createSpy('$navBack');
59+
el.triggerHandler('click');
60+
expect(el.scope().$navBack).toHaveBeenCalled();
6461
});
6562

66-
it('should not add onTap if ngClick is defined', function() {
67-
spyOn(ionic, 'on');
63+
it('should do ngClick expression if defined', function() {
6864
var el = setup('ng-click="doSomething()"');
69-
expect(ionic.on).not.toHaveBeenCalled();
65+
el.scope().$navBack = jasmine.createSpy('$navBack');
66+
el.scope().doSomething = jasmine.createSpy('doSomething');
67+
el.triggerHandler('click');
68+
expect(el.scope().$navBack).not.toHaveBeenCalled();
69+
expect(el.scope().doSomething).toHaveBeenCalled();
7070
});
7171
});

0 commit comments

Comments
 (0)