From 4f6c26642c32293b29dd3cbf43baaff292921d71 Mon Sep 17 00:00:00 2001 From: VTHINKXIE Date: Thu, 24 May 2018 18:34:51 +0800 Subject: [PATCH] fix(module:menu): fix menu ngfor bug (#1519) --- components/menu/nz-menu.spec.ts | 41 ++++++++++++++++++- components/menu/nz-submenu.component.ts | 4 +- .../share/nz-codebox/nz-codebox.component.ts | 3 +- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/components/menu/nz-menu.spec.ts b/components/menu/nz-menu.spec.ts index f54b97e4937..e23baf34114 100644 --- a/components/menu/nz-menu.spec.ts +++ b/components/menu/nz-menu.spec.ts @@ -28,7 +28,7 @@ describe('menu', () => { const dir = 'ltr'; TestBed.configureTestingModule({ imports : [ NzMenuModule, NoopAnimationsModule, NoopAnimationsModule ], - declarations: [ NzDemoMenuHorizontalComponent, NzDemoMenuInlineComponent, NzDemoMenuInlineCollapsedComponent, NzDemoMenuSiderCurrentComponent, NzDemoMenuThemeComponent, NzDemoMenuSwitchModeComponent, NzTestMenuHorizontalComponent, NzTestMenuInlineComponent ], + declarations: [ NzDemoMenuHorizontalComponent, NzDemoMenuInlineComponent, NzDemoMenuInlineCollapsedComponent, NzDemoMenuSiderCurrentComponent, NzDemoMenuThemeComponent, NzDemoMenuSwitchModeComponent, NzTestMenuHorizontalComponent, NzTestMenuInlineComponent, NzDemoMenuNgForComponent ], schemas : [ NO_ERRORS_SCHEMA ], providers : [ { provide: Directionality, useFactory: () => ({ value: dir }) }, @@ -423,6 +423,11 @@ describe('menu', () => { expect(submenu.nativeElement.classList.contains('ant-menu-submenu-open')).toBe(false); })); }); + describe('ng-for', () => { + it('should ng for works fine', () => { + TestBed.createComponent(NzDemoMenuNgForComponent).detectChanges(); + }); + }); }); }); @@ -496,3 +501,37 @@ export class NzTestMenuInlineComponent { @ViewChild(NzSubMenuComponent) subsmenu: NzSubMenuComponent; @ViewChild('menuitem', { read: ElementRef }) menuitem: ElementRef; } + +@Component({ + selector: 'nz-demo-menu-ngfor', + template: ` + `, + styles : [] +}) +export class NzDemoMenuNgForComponent { + menus = [ + { + text : 'level1', + children: [ + { + text : 'level2', + children: [ + { text: 'level3' } + ] + } + ] + } + ]; +} diff --git a/components/menu/nz-submenu.component.ts b/components/menu/nz-submenu.component.ts index 8be72f3a7dc..99b3fd82826 100644 --- a/components/menu/nz-submenu.component.ts +++ b/components/menu/nz-submenu.component.ts @@ -131,7 +131,7 @@ import { NzMenuDirective } from './nz-menu.directive'; `, styles : [ - ` + ` .ant-menu-submenu-placement-bottomLeft { top: 6px; position: relative; @@ -372,7 +372,7 @@ export class NzSubMenuComponent implements OnInit, OnDestroy, AfterContentInit { if (this.subMenus && this.subMenus.length) { this.subMenus.filter(x => x !== this).forEach(menu => { if (this.subMenuMode === 'inline') { - menu.level = this.level + 1; + Promise.resolve().then(() => menu.level = this.level + 1); } menu.isInSubMenu = true; }); diff --git a/site_scripts/_site/src/app/share/nz-codebox/nz-codebox.component.ts b/site_scripts/_site/src/app/share/nz-codebox/nz-codebox.component.ts index dfef0d77d55..235382e9ec2 100644 --- a/site_scripts/_site/src/app/share/nz-codebox/nz-codebox.component.ts +++ b/site_scripts/_site/src/app/share/nz-codebox/nz-codebox.component.ts @@ -243,6 +243,7 @@ export class AppModule { } description : 'Created with <3 by the StackBlitz SDK!', template : 'angular-cli', dependencies: { + 'rxjs' : '^5.0.0', '@angular/cdk' : '^5.0.0', '@angular/core' : '^5.0.0', '@angular/forms' : '^5.0.0', @@ -254,7 +255,7 @@ export class AppModule { } '@angular/router' : '^5.0.0', '@angular/animations' : '^5.0.0', 'date-fns' : '^1.29.0', - 'ng-zorro-antd' : 'next' + 'ng-zorro-antd' : '^0.7.0' }, tags : [ 'stackblitz', 'sdk' ] });