From 1188730f10bcc8f50d7991660504aa1b6f916258 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Wed, 8 Jun 2016 22:08:28 -0500 Subject: [PATCH] fix(scrollView): ensure scroll element exists for event listeners Related #6104 --- src/util/scroll-view.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/util/scroll-view.ts b/src/util/scroll-view.ts index 281137ec85..75d5006132 100644 --- a/src/util/scroll-view.ts +++ b/src/util/scroll-view.ts @@ -132,18 +132,20 @@ export class ScrollView { this._cb = onScrollCallback; this._pos = []; - this._el.addEventListener('touchstart', this._start.bind(this)); - this._el.addEventListener('touchmove', this._move.bind(this)); - this._el.addEventListener('touchend', this._end.bind(this)); - - this._el.parentElement.classList.add('js-scroll'); + if (this._el) { + this._el.addEventListener('touchstart', this._start.bind(this)); + this._el.addEventListener('touchmove', this._move.bind(this)); + this._el.addEventListener('touchend', this._end.bind(this)); + this._el.parentElement.classList.add('js-scroll'); + } return () => { - this._el.removeEventListener('touchstart', this._start.bind(this)); - this._el.removeEventListener('touchmove', this._move.bind(this)); - this._el.removeEventListener('touchend', this._end.bind(this)); - - this._el.parentElement.classList.remove('js-scroll'); + if (this._el) { + this._el.removeEventListener('touchstart', this._start.bind(this)); + this._el.removeEventListener('touchmove', this._move.bind(this)); + this._el.removeEventListener('touchend', this._end.bind(this)); + this._el.parentElement.classList.remove('js-scroll'); + } }; }