Skip to content

Commit 4dffc5f

Browse files
committed
fix(navClear): only set viewOptions if click leads to state change
Closes #1043
1 parent d6c960c commit 4dffc5f

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

js/ext/angular/src/directive/ionicViewState.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -300,19 +300,33 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
300300
*/
301301
.directive('navClear', [
302302
'$ionicViewService',
303-
function($ionicViewService) {
303+
'$state',
304+
'$location',
305+
'$window',
306+
'$rootScope',
307+
function($ionicViewService, $location, $state, $window, $rootScope) {
308+
$rootScope.$on('$stateChangeError', function() {
309+
$ionicViewService.nextViewOptions(null);
310+
});
304311
return {
305312
priority: 100,
306313
restrict: 'AC',
307314
compile: function($element) {
308315
return { pre: prelink };
309-
function prelink($scope, $element) {
310-
$element.on('click', function(e){
311-
$ionicViewService.nextViewOptions({
312-
disableAnimate: true,
313-
disableBack: true
316+
function prelink($scope, $element, $attrs) {
317+
var unregisterListener;
318+
function listenForStateChange() {
319+
unregisterListener = $scope.$on('$stateChangeStart', function() {
320+
$ionicViewService.nextViewOptions({
321+
disableAnimate: true,
322+
disableBack: true
323+
});
324+
unregisterListener();
314325
});
315-
});
326+
$window.setTimeout(unregisterListener, 300);
327+
}
328+
329+
$element.on('click', listenForStateChange);
316330
}
317331
}
318332
};
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
1-
describe('navClear directive', function() {
1+
ddescribe('navClear directive', function() {
22
beforeEach(module('ionic'));
3-
it('should call nextViewOptions on click', inject(function($rootScope, $compile, $ionicViewService) {
3+
4+
it('should call nextViewOptions on click & stateChangeSuccess', inject(function($rootScope, $compile, $ionicViewService) {
45
spyOn($ionicViewService, 'nextViewOptions');
56
var el = $compile('<div nav-clear>')($rootScope.$new());
7+
68
expect($ionicViewService.nextViewOptions).not.toHaveBeenCalled();
79
el.triggerHandler('click');
10+
el.scope().$broadcast('$stateChangeStart');
811
expect($ionicViewService.nextViewOptions).toHaveBeenCalled();
912
expect($ionicViewService.nextViewOptions.mostRecentCall.args[0]).toEqual({
1013
disableAnimate: true,
1114
disableBack: true
1215
});
1316
}));
14-
15-
it('should run its click action before ngClick', inject(function($rootScope, $compile, $ionicViewService) {
16-
spyOn($ionicViewService, 'nextViewOptions');
17-
var el = $compile('<div nav-clear ng-click="method()">')($rootScope.$new());
18-
var done = false;
19-
20-
//navClear should've called nextViewOptions by the time the ngClick handler runs
21-
el.scope().method = function() {
22-
expect($ionicViewService.nextViewOptions).toHaveBeenCalled();
23-
done = true;
24-
};
25-
el.triggerHandler('click');
26-
expect(done).toBe(true);
27-
}));
2817
});

0 commit comments

Comments
 (0)