Skip to content

Commit

Permalink
fix(menu): trigger change detection after setting max-height (#349)
Browse files Browse the repository at this point in the history
Closes #263 
To animate menu expanding we need to know a height of all expanded children.
Since children can't be accessed before AfterViewInit hook, we have to calc
and set 'maxHeight' there, but it causing ExpressionChangedAfterItHasBeenCheckedError
error. Since 'maxHeight' can't be calculated earlier, we have to trigger change detection
again. This is a common workaround for this error.
  • Loading branch information
yggg authored and nnixaa committed Apr 5, 2018
1 parent c9a39a2 commit 8c10372
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/framework/theme/components/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
AfterViewInit,
PLATFORM_ID,
Inject,
ChangeDetectorRef,
} from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { Router, NavigationEnd } from '@angular/router';
Expand Down Expand Up @@ -56,6 +57,7 @@ export class NbMenuItemComponent implements AfterViewInit, OnDestroy {
constructor(
private menuService: NbMenuService,
@Inject(PLATFORM_ID) private platformId: Object,
private changeDetection: ChangeDetectorRef,
) { }

ngAfterViewInit() {
Expand All @@ -70,10 +72,9 @@ export class NbMenuItemComponent implements AfterViewInit, OnDestroy {
.pipe(takeWhile(() => this.alive))
.subscribe(() => this.updateMaxHeight());

setTimeout(() => {
this.updateSubmenuHeight();
this.updateMaxHeight();
});
this.updateSubmenuHeight();
this.updateMaxHeight();
this.changeDetection.detectChanges();
}

ngOnDestroy() {
Expand Down

0 comments on commit 8c10372

Please sign in to comment.