55
66import { ConnectionPositionPair , Overlay , OverlayRef } from '@angular/cdk/overlay' ;
77import { TemplatePortal } from '@angular/cdk/portal' ;
8- import { Injectable , NgZone } from '@angular/core' ;
8+ import { EmbeddedViewRef , Injectable , NgZone } from '@angular/core' ;
99import { fromEvent , merge , Subscription } from 'rxjs' ;
1010import { filter , first } from 'rxjs/operators' ;
1111
12+ import { NzSafeAny } from 'ng-zorro-antd/core/types' ;
13+
1214import { NzContextMenuServiceModule } from './context-menu.service.module' ;
1315import { NzDropdownMenuComponent } from './dropdown-menu.component' ;
1416
15- const listOfPositions = [
17+ const LIST_OF_POSITIONS = [
1618 new ConnectionPositionPair ( { originX : 'start' , originY : 'top' } , { overlayX : 'start' , overlayY : 'top' } ) ,
1719 new ConnectionPositionPair ( { originX : 'start' , originY : 'top' } , { overlayX : 'start' , overlayY : 'bottom' } ) ,
1820 new ConnectionPositionPair ( { originX : 'start' , originY : 'top' } , { overlayX : 'end' , overlayY : 'bottom' } ) ,
@@ -28,7 +30,10 @@ export class NzContextMenuService {
2830
2931 constructor ( private ngZone : NgZone , private overlay : Overlay ) { }
3032
31- create ( $event : MouseEvent | { x : number ; y : number } , nzDropdownMenuComponent : NzDropdownMenuComponent ) : void {
33+ create (
34+ $event : MouseEvent | { x : number ; y : number } ,
35+ nzDropdownMenuComponent : NzDropdownMenuComponent
36+ ) : EmbeddedViewRef < NzSafeAny > {
3237 this . close ( true ) ;
3338 const { x, y } = $event ;
3439 if ( $event instanceof MouseEvent ) {
@@ -37,7 +42,7 @@ export class NzContextMenuService {
3742 const positionStrategy = this . overlay
3843 . position ( )
3944 . flexibleConnectedTo ( { x, y } )
40- . withPositions ( listOfPositions )
45+ . withPositions ( LIST_OF_POSITIONS )
4146 . withTransformOriginOn ( '.ant-dropdown' ) ;
4247 this . overlayRef = this . overlay . create ( {
4348 positionStrategy,
@@ -64,7 +69,7 @@ export class NzContextMenuService {
6469 )
6570 ) ;
6671
67- this . overlayRef . attach (
72+ return this . overlayRef . attach (
6873 new TemplatePortal ( nzDropdownMenuComponent . templateRef , nzDropdownMenuComponent . viewContainerRef )
6974 ) ;
7075 }
0 commit comments