mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
ionicScrollController: do not try to remember scorll if no viewId
This commit is contained in:
@@ -81,17 +81,18 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca
|
||||
if (e.defaultPrevented) { return; }
|
||||
e.preventDefault();
|
||||
|
||||
var viewId = historyData.viewId;
|
||||
var viewId = historyData && historyData.viewId;
|
||||
if (viewId) {
|
||||
self.rememberScrollPosition(viewId);
|
||||
self.scrollToRememberedPosition();
|
||||
|
||||
self.rememberScrollPosition(viewId);
|
||||
self.scrollToRememberedPosition();
|
||||
|
||||
backListenDone = $rootScope.$on('$viewHistory.viewBack', function(e, fromViewId, toViewId) {
|
||||
//When going back from this view, forget its saved scroll position
|
||||
if (viewId === fromViewId) {
|
||||
self.forgetScrollPosition();
|
||||
}
|
||||
});
|
||||
backListenDone = $rootScope.$on('$viewHistory.viewBack', function(e, fromViewId, toViewId) {
|
||||
//When going back from this view, forget its saved scroll position
|
||||
if (viewId === fromViewId) {
|
||||
self.forgetScrollPosition();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$timeout(function() {
|
||||
|
||||
@@ -91,6 +91,17 @@ describe('$ionicScroll Controller', function() {
|
||||
expect(ctrl.scrollView.resize).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not remember scroll position on $viewContentLoaded if no viewId', function() {
|
||||
var historyData = {};
|
||||
setup();
|
||||
spyOn(ctrl, 'rememberScrollPosition');
|
||||
spyOn(ctrl, 'scrollToRememberedPosition');
|
||||
scope.$broadcast('$viewContentLoaded', historyData);
|
||||
timeout.flush();
|
||||
expect(ctrl.rememberScrollPosition).not.toHaveBeenCalledWith();
|
||||
expect(ctrl.scrollToRememberedPosition).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should remember scroll position on $viewContentLoaded event', function() {
|
||||
var historyData = { viewId: '1' };
|
||||
setup();
|
||||
|
||||
Reference in New Issue
Block a user