mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(viewService): No error on clearHistory for empty history
This commit is contained in:
32
js/angular/service/viewService.js
vendored
32
js/angular/service/viewService.js
vendored
@@ -550,21 +550,23 @@ function($rootScope, $state, $location, $window, $injector, $animate, $ionicNavV
|
||||
histories = $rootScope.$viewHistory.histories,
|
||||
currentView = $rootScope.$viewHistory.currentView;
|
||||
|
||||
for(var historyId in histories) {
|
||||
if(histories) {
|
||||
for(var historyId in histories) {
|
||||
|
||||
if(histories[historyId].stack) {
|
||||
histories[historyId].stack = [];
|
||||
histories[historyId].cursor = -1;
|
||||
}
|
||||
|
||||
if(currentView && currentView.historyId === historyId) {
|
||||
currentView.backViewId = null;
|
||||
currentView.forwardViewId = null;
|
||||
histories[historyId].stack.push(currentView);
|
||||
} else if(histories[historyId].destroy) {
|
||||
histories[historyId].destroy();
|
||||
}
|
||||
|
||||
if(histories[historyId].stack) {
|
||||
histories[historyId].stack = [];
|
||||
histories[historyId].cursor = -1;
|
||||
}
|
||||
|
||||
if(currentView.historyId === historyId) {
|
||||
currentView.backViewId = null;
|
||||
currentView.forwardViewId = null;
|
||||
histories[historyId].stack.push(currentView);
|
||||
} else if(histories[historyId].destroy) {
|
||||
histories[historyId].destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(var viewId in $rootScope.$viewHistory.views) {
|
||||
@@ -573,7 +575,9 @@ function($rootScope, $state, $location, $window, $injector, $animate, $ionicNavV
|
||||
}
|
||||
}
|
||||
|
||||
this.setNavViews(currentView.viewId);
|
||||
if(currentView) {
|
||||
this.setNavViews(currentView.viewId);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -697,6 +697,10 @@ describe('Ionic View Service', function() {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not error when clearing empty history', function() {
|
||||
expect(viewService.clearHistory.bind(null)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should create a viewService view', inject(function($location) {
|
||||
var newView = viewService.createView();
|
||||
expect(newView).toEqual(null);
|
||||
|
||||
Reference in New Issue
Block a user