diff --git a/js/ext/angular/src/directive/ionicViewState.js b/js/ext/angular/src/directive/ionicViewState.js index dadac6e895..4e48ac7c41 100644 --- a/js/ext/angular/src/directive/ionicViewState.js +++ b/js/ext/angular/src/directive/ionicViewState.js @@ -300,19 +300,33 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu */ .directive('navClear', [ '$ionicViewService', -function($ionicViewService) { + '$state', + '$location', + '$window', + '$rootScope', +function($ionicViewService, $location, $state, $window, $rootScope) { + $rootScope.$on('$stateChangeError', function() { + $ionicViewService.nextViewOptions(null); + }); return { priority: 100, restrict: 'AC', compile: function($element) { return { pre: prelink }; - function prelink($scope, $element) { - $element.on('click', function(e){ - $ionicViewService.nextViewOptions({ - disableAnimate: true, - disableBack: true + function prelink($scope, $element, $attrs) { + var unregisterListener; + function listenForStateChange() { + unregisterListener = $scope.$on('$stateChangeStart', function() { + $ionicViewService.nextViewOptions({ + disableAnimate: true, + disableBack: true + }); + unregisterListener(); }); - }); + $window.setTimeout(unregisterListener, 300); + } + + $element.on('click', listenForStateChange); } } }; diff --git a/js/ext/angular/test/directive/ionicNavClear.unit.js b/js/ext/angular/test/directive/ionicNavClear.unit.js index 6baeb86393..1598c3cc77 100644 --- a/js/ext/angular/test/directive/ionicNavClear.unit.js +++ b/js/ext/angular/test/directive/ionicNavClear.unit.js @@ -1,28 +1,17 @@ -describe('navClear directive', function() { +ddescribe('navClear directive', function() { beforeEach(module('ionic')); - it('should call nextViewOptions on click', inject(function($rootScope, $compile, $ionicViewService) { + + it('should call nextViewOptions on click & stateChangeSuccess', inject(function($rootScope, $compile, $ionicViewService) { spyOn($ionicViewService, 'nextViewOptions'); var el = $compile('