diff --git a/js/angular/controller/navBarController.js b/js/angular/controller/navBarController.js index 618c6a2ca3..a08f566f93 100644 --- a/js/angular/controller/navBarController.js +++ b/js/angular/controller/navBarController.js @@ -25,10 +25,9 @@ function($scope, $element, $attrs, $ionicViewService, $animate, $compile, $ionic $element[0].querySelector('.buttons.right-buttons') ); - this.back = function(e) { + this.back = function() { var backView = $ionicViewService.getBackView(); backView && backView.go(); - e && (e.alreadyHandled = true); return false; }; diff --git a/js/angular/directive/navBackButton.js b/js/angular/directive/navBackButton.js index 12eba0a7ce..1f3b365c79 100644 --- a/js/angular/directive/navBackButton.js +++ b/js/angular/directive/navBackButton.js @@ -65,10 +65,9 @@ IonicModule '$animate', '$rootScope', '$sanitize', - '$ionicNavBarConfig', - -function($animate, $rootScope, $sanitize, $ionicNavBarConfig) { + '$ionicNgClick', +function($animate, $rootScope, $sanitize, $ionicNavBarConfig, $ionicNgClick) { var backIsShown = false; //If the current viewstate does not allow a back button, //always hide it. @@ -80,23 +79,19 @@ function($animate, $rootScope, $sanitize, $ionicNavBarConfig) { require: '^ionNavBar', compile: function(tElement, tAttrs) { tElement.addClass('button back-button ng-hide'); - + return function($scope, $element, $attr, navBarCtrl) { - console.log($attr.textFromTitle); // Add a default back button icon based on the nav config, unless one is set if($element[0].className.indexOf('ion-') < 0) { $element.addClass($ionicNavBarConfig.backButtonIcon); } - if (!$attr.ngClick) { - $scope.$navBack = navBarCtrl.back; - $element.on('click', function(event){ - $scope.$apply(function() { - $scope.$navBack(event); - }); - }); + //Default to ngClick going back, but don't override a custom one + if (!isDefined($attr.ngClick)) { + $ionicNgClick($scope, $element, navBarCtrl.back); } + //Make sure both that a backButton is allowed in the first place, //and that it is shown by the current view. $scope.$watch(function() { diff --git a/js/angular/directive/ngClick.js b/js/angular/directive/ngClick.js index c29ede8609..56951ae3d0 100644 --- a/js/angular/directive/ngClick.js +++ b/js/angular/directive/ngClick.js @@ -13,7 +13,9 @@ IonicModule */ .factory('$ionicNgClick', ['$parse', function($parse) { return function(scope, element, clickExpr) { - var clickHandler = $parse(clickExpr); + var clickHandler = angular.isFunction(clickExpr) ? + clickExpr : + $parse(clickExpr); element.on('click', function(event) { scope.$apply(function() { diff --git a/test/html/list-simple.html b/test/html/list-simple.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/unit/angular/directive/navBackButton.unit.js b/test/unit/angular/directive/navBackButton.unit.js index b6958c8f6c..1189358fb4 100644 --- a/test/unit/angular/directive/navBackButton.unit.js +++ b/test/unit/angular/directive/navBackButton.unit.js @@ -1,4 +1,3 @@ - describe('ionNavBackButton directive', function() { beforeEach(module('ionic')); @@ -62,11 +61,11 @@ describe('ionNavBackButton directive', function() { expect(el.children().eq(0)[0].tagName.toLowerCase()).toBe('b'); }); - it('should $navBack on click by default', function() { + it('should go back on click by default', function() { var el = setup(); - el.scope().$navBack = jasmine.createSpy('$navBack'); + expect(el.controller('ionNavBar').back).not.toHaveBeenCalled(); el.triggerHandler('click'); - expect(el.scope().$navBack).toHaveBeenCalled(); + expect(el.controller('ionNavBar').back).toHaveBeenCalled(); }); it('should do ngClick expression if defined', function() { @@ -80,7 +79,7 @@ describe('ionNavBackButton directive', function() { describe('ionNavBackButton directive: Platforms', function() { - describe('ionNavBackButton directive: iOS Platform', function() { + describe('ionNavBackButton directive: iOS Platform', function() { beforeEach(function($provide) { TestUtil.setPlatform('ios'); }); diff --git a/test/unit/angular/directive/navBar.unit.js b/test/unit/angular/directive/navBar.unit.js index fba07817e8..0cfebca6a6 100644 --- a/test/unit/angular/directive/navBar.unit.js +++ b/test/unit/angular/directive/navBar.unit.js @@ -49,11 +49,9 @@ describe('ionNavBar', function() { it('should go back', inject(function($ionicViewService) { var ctrl = setup(); - var e = { alreadyHandled: false }; - ctrl.back(e); + ctrl.back(); expect($ionicViewService.getBackView).toHaveBeenCalled(); expect(backView.go).toHaveBeenCalled(); - expect(e.alreadyHandled).toBe(true); })); it('should align', function() { @@ -308,7 +306,7 @@ describe('ionNavBar', function() { describe('iOS', function() { beforeEach(module('ionic', function($provide) { TestUtil.setPlatform('ios'); - $provide.constant('$ionicNavBarConfig', { + $provide.constant('$ionicNavBarConfig', { alignTitle: 'center', transition: 'nav-title-slide-ios7', backButtonIcon: 'ion-ios7-arrow-back' @@ -330,7 +328,7 @@ describe('ionNavBar', function() { describe('Android', function() { beforeEach(module('ionic', function($provide) { TestUtil.setPlatform('android'); - $provide.constant('$ionicNavBarConfig', { + $provide.constant('$ionicNavBarConfig', { alignTitle: 'left', transition: 'no-animation', backButtonIcon: 'ion-android-back'