Skip to content

Commit

Permalink
fix(layout): access view child property after view init (#2249)
Browse files Browse the repository at this point in the history
  • Loading branch information
yggg committed Mar 5, 2020
1 parent 737ffe2 commit 5bb21a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('NbAdjustableConnectedPositionStrategy', () => {

// Have to create layout component as it's required for scroll service to work properly.
// Also it registers overlay container so we don't have to create it manually.
TestBed.createComponent(NbLayoutComponent);
TestBed.createComponent(NbLayoutComponent).detectChanges();

overlayHostElement = document.createElement('div');
overlayHostElement.style.width = '10px';
Expand Down
33 changes: 14 additions & 19 deletions src/framework/theme/components/layout/layout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,25 +274,6 @@ export class NbLayoutComponent implements AfterViewInit, OnDestroy {
listener.complete();
});

this.scrollService.onGetPosition()
.pipe(
takeUntil(this.destroy$),
)
.subscribe(({ listener }) => {
listener.next(this.getScrollPosition());
listener.complete();
});

this.scrollTop
.shouldRestore()
.pipe(
filter(() => this.restoreScrollTopValue),
takeUntil(this.destroy$),
)
.subscribe(() => {
this.scroll(0, 0);
});

this.scrollService
.onScrollableChange()
.pipe(
Expand All @@ -318,6 +299,20 @@ export class NbLayoutComponent implements AfterViewInit, OnDestroy {
}

ngAfterViewInit() {
this.scrollService.onGetPosition()
.pipe(takeUntil(this.destroy$))
.subscribe(({ listener }) => {
listener.next(this.getScrollPosition());
listener.complete();
});

this.scrollTop.shouldRestore()
.pipe(filter(
() => this.restoreScrollTopValue),
takeUntil(this.destroy$),
)
.subscribe(() => this.scroll(0, 0));

this.layoutDirectionService.onDirectionChange()
.pipe(takeUntil(this.destroy$))
.subscribe(direction => this.document.dir = direction);
Expand Down

0 comments on commit 5bb21a7

Please sign in to comment.