Skip to content

Commit ca3d897

Browse files
committed
don't throw exceptions if the view is destroyed
`resize()` is a promise, and the `$destroy` event can fire before it finishes, nulling out `scrollView` which subsequently throws an exception because we are trying to call methods on `null`.
1 parent 2c706c7 commit ca3d897

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Diff for: js/angular/controller/scrollController.js

+21
Original file line numberDiff line numberDiff line change
@@ -108,43 +108,64 @@ function($scope,
108108

109109
self.scrollTop = function(shouldAnimate) {
110110
self.resize().then(function() {
111+
if (!scrollView) {
112+
return;
113+
}
111114
scrollView.scrollTo(0, 0, !!shouldAnimate);
112115
});
113116
};
114117

115118
self.scrollBottom = function(shouldAnimate) {
116119
self.resize().then(function() {
120+
if (!scrollView) {
121+
return;
122+
}
117123
var max = scrollView.getScrollMax();
118124
scrollView.scrollTo(max.left, max.top, !!shouldAnimate);
119125
});
120126
};
121127

122128
self.scrollTo = function(left, top, shouldAnimate) {
123129
self.resize().then(function() {
130+
if (!scrollView) {
131+
return;
132+
}
124133
scrollView.scrollTo(left, top, !!shouldAnimate);
125134
});
126135
};
127136

128137
self.zoomTo = function(zoom, shouldAnimate, originLeft, originTop) {
129138
self.resize().then(function() {
139+
if (!scrollView) {
140+
return;
141+
}
130142
scrollView.zoomTo(zoom, !!shouldAnimate, originLeft, originTop);
131143
});
132144
};
133145

134146
self.zoomBy = function(zoom, shouldAnimate, originLeft, originTop) {
135147
self.resize().then(function() {
148+
if (!scrollView) {
149+
return;
150+
}
136151
scrollView.zoomBy(zoom, !!shouldAnimate, originLeft, originTop);
137152
});
138153
};
139154

140155
self.scrollBy = function(left, top, shouldAnimate) {
141156
self.resize().then(function() {
157+
if (!scrollView) {
158+
return;
159+
}
142160
scrollView.scrollBy(left, top, !!shouldAnimate);
143161
});
144162
};
145163

146164
self.anchorScroll = function(shouldAnimate) {
147165
self.resize().then(function() {
166+
if (!scrollView) {
167+
return;
168+
}
148169
var hash = $location.hash();
149170
var elm = hash && $document[0].getElementById(hash);
150171
if (!(hash && elm)) {

0 commit comments

Comments
 (0)