Skip to content

Commit cf15f8f

Browse files
committed
fix the problem of : 'this.stickyParent' might be 'null'
1 parent 7427dd1 commit cf15f8f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/lib/sticky-header/sticky-header-dir.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class CdkStickyHeader implements OnDestroy, AfterViewInit {
6060
public element: HTMLElement;
6161

6262
// the upper container element with the 'cdkStickyRegion' tag
63-
public stickyParent: HTMLElement;
63+
public stickyParent: HTMLElement | null;
6464
public upperScrollableContainer: HTMLElement;
6565

6666
/**
@@ -147,6 +147,9 @@ export class CdkStickyHeader implements OnDestroy, AfterViewInit {
147147
* when to start, when to finish)
148148
*/
149149
defineRestrictions(): void {
150+
if(this.stickyParent == null) {
151+
return;
152+
}
150153
let containerTop: any = this.stickyParent.getBoundingClientRect();
151154
let elemHeight: number = this.element.offsetHeight;
152155
let containerHeight: number = this.getCssNumber(this.stickyParent, 'height');
@@ -225,6 +228,10 @@ export class CdkStickyHeader implements OnDestroy, AfterViewInit {
225228
unstuckElement(): void {
226229
this.isStuck = false;
227230

231+
if(this.stickyParent == null) {
232+
return;
233+
}
234+
228235
this.element.classList.add(STICK_END_CLASS);
229236
this.stickyParent.style.position = 'relative';
230237
let unstuckCss: any = {

0 commit comments

Comments
 (0)