Skip to content

Commit

Permalink
fix(module:dropdown): fix dropdown SSR bug (#3628)
Browse files Browse the repository at this point in the history
  • Loading branch information
vthinkxie committed Jun 22, 2019
1 parent aad02a5 commit ade1abd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions components/dropdown/nz-dropdown.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
OverlayConfig,
OverlayRef
} from '@angular/cdk/overlay';
import { Platform } from '@angular/cdk/platform';
import { TemplatePortal } from '@angular/cdk/portal';
import {
AfterViewInit,
Expand Down Expand Up @@ -171,8 +172,10 @@ export class NzDropDownDirective implements AfterViewInit, OnDestroy, OnChanges
}

private setTriggerWidth(): void {
const element = this.nzMatchWidthElement ? this.nzMatchWidthElement.nativeElement : this.el;
this.triggerWidth = element.getBoundingClientRect().width;
if (this.platform.isBrowser) {
const element = this.nzMatchWidthElement ? this.nzMatchWidthElement.nativeElement : this.el;
this.triggerWidth = element.getBoundingClientRect().width;
}
}

initActionSubscribe(): void {
Expand Down Expand Up @@ -221,6 +224,7 @@ export class NzDropDownDirective implements AfterViewInit, OnDestroy, OnChanges
public elementRef: ElementRef,
private renderer: Renderer2,
private overlay: Overlay,
private platform: Platform,
private viewContainerRef: ViewContainerRef
) {
renderer.addClass(elementRef.nativeElement, 'ant-dropdown-trigger');
Expand Down
2 changes: 2 additions & 0 deletions components/dropdown/nz-dropdown.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { NzAddOnModule, NzNoAnimationModule, NzOverlayModule } from 'ng-zorro-an
import { NzIconModule } from 'ng-zorro-antd/icon';
import { NzMenuModule } from 'ng-zorro-antd/menu';

import { PlatformModule } from '@angular/cdk/platform';
import { NzContextMenuService } from './nz-context-menu.service';
import { NzDropDownADirective } from './nz-dropdown-a.directive';
import { NzDropDownButtonComponent } from './nz-dropdown-button.component';
Expand All @@ -33,6 +34,7 @@ import { NzDropdownService } from './nz-dropdown.service';
NzButtonModule,
NzMenuModule,
NzIconModule,
PlatformModule,
NzNoAnimationModule,
NzOverlayModule,
NzAddOnModule
Expand Down

0 comments on commit ade1abd

Please sign in to comment.