From 3e1cbebdbe6589b1bb3c0c84a0eff1f56b04b554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=A7=E8=A1=A1?= Date: Sat, 23 Sep 2017 19:24:44 +0800 Subject: [PATCH] fix(module:menu): fix submenu ExpressionChangedAfterItHasBeenCheckedError close #367 --- src/components/menu/nz-menu.component.ts | 10 +++++++++- src/components/menu/nz-submenu.component.ts | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/menu/nz-menu.component.ts b/src/components/menu/nz-menu.component.ts index 915798e49b0..6c3973d1fbd 100644 --- a/src/components/menu/nz-menu.component.ts +++ b/src/components/menu/nz-menu.component.ts @@ -35,10 +35,12 @@ export class NzMenuComponent implements OnChanges, AfterViewInit { @Input() nzMode: NzMode = 'vertical'; @Input() nzTheme: 'light' | 'dark' = 'light'; @Input() nzClickActive = true; + @Input() get nzInlineCollapsed(): boolean { return this._nzInlineCollapsed; } + set nzInlineCollapsed(state: boolean) { this._nzInlineCollapsed = state; if (!this.isInit) { @@ -143,7 +145,7 @@ export class NzMenuComponent implements OnChanges, AfterViewInit { } reductionSubMenus() { - this._subMenusOpenIndex.forEach(i => this.subMenus[i].nzOpen = true); + this._subMenusOpenIndex.forEach(i => this.subMenus[ i ].nzOpen = true); this._subMenusOpenIndex = []; } @@ -155,4 +157,10 @@ export class NzMenuComponent implements OnChanges, AfterViewInit { this.subMenus.forEach(subMenu => subMenu.isInDropDown = value); }); } + + setHasSubMenu(value: boolean) { + setTimeout(_ => { + this.hasSubMenu = value; + }) + } } diff --git a/src/components/menu/nz-submenu.component.ts b/src/components/menu/nz-submenu.component.ts index 79fdf26290e..0591fcd7866 100644 --- a/src/components/menu/nz-submenu.component.ts +++ b/src/components/menu/nz-submenu.component.ts @@ -140,7 +140,7 @@ export class NzSubMenuComponent implements OnInit, OnDestroy, AfterViewInit { constructor(public nzMenuComponent: NzMenuComponent, public cd: ChangeDetectorRef) { - this.nzMenuComponent.hasSubMenu = true; + this.nzMenuComponent.setHasSubMenu(true); this.nzMenuComponent.subMenus.push(this); }