5
5
6
6
import { ConnectionPositionPair , Overlay , OverlayRef } from '@angular/cdk/overlay' ;
7
7
import { TemplatePortal } from '@angular/cdk/portal' ;
8
- import { Injectable , NgZone } from '@angular/core' ;
8
+ import { EmbeddedViewRef , Injectable , NgZone } from '@angular/core' ;
9
9
import { fromEvent , merge , Subscription } from 'rxjs' ;
10
10
import { filter , first } from 'rxjs/operators' ;
11
11
12
+ import { NzSafeAny } from 'ng-zorro-antd/core/types' ;
13
+
12
14
import { NzContextMenuServiceModule } from './context-menu.service.module' ;
13
15
import { NzDropdownMenuComponent } from './dropdown-menu.component' ;
14
16
15
- const listOfPositions = [
17
+ const LIST_OF_POSITIONS = [
16
18
new ConnectionPositionPair ( { originX : 'start' , originY : 'top' } , { overlayX : 'start' , overlayY : 'top' } ) ,
17
19
new ConnectionPositionPair ( { originX : 'start' , originY : 'top' } , { overlayX : 'start' , overlayY : 'bottom' } ) ,
18
20
new ConnectionPositionPair ( { originX : 'start' , originY : 'top' } , { overlayX : 'end' , overlayY : 'bottom' } ) ,
@@ -28,7 +30,10 @@ export class NzContextMenuService {
28
30
29
31
constructor ( private ngZone : NgZone , private overlay : Overlay ) { }
30
32
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 > {
32
37
this . close ( true ) ;
33
38
const { x, y } = $event ;
34
39
if ( $event instanceof MouseEvent ) {
@@ -37,7 +42,7 @@ export class NzContextMenuService {
37
42
const positionStrategy = this . overlay
38
43
. position ( )
39
44
. flexibleConnectedTo ( { x, y } )
40
- . withPositions ( listOfPositions )
45
+ . withPositions ( LIST_OF_POSITIONS )
41
46
. withTransformOriginOn ( '.ant-dropdown' ) ;
42
47
this . overlayRef = this . overlay . create ( {
43
48
positionStrategy,
@@ -64,7 +69,7 @@ export class NzContextMenuService {
64
69
)
65
70
) ;
66
71
67
- this . overlayRef . attach (
72
+ return this . overlayRef . attach (
68
73
new TemplatePortal ( nzDropdownMenuComponent . templateRef , nzDropdownMenuComponent . viewContainerRef )
69
74
) ;
70
75
}
0 commit comments