forked from vamidi/visualne-context-menu-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.component.ts
More file actions
50 lines (43 loc) · 1.36 KB
/
Copy pathcontext.component.ts
File metadata and controls
50 lines (43 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import {
Component,
Input,
OnInit,
ChangeDetectionStrategy,
} from '@angular/core';
import { ContextMenuService } from './context-menu.service';
import { ComponentType } from '@angular/cdk/overlay';
import { Subscription } from 'rxjs';
@Component({
template: '',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ContextComponent implements OnInit
{
@Input() el: HTMLElement | null = null;
@Input() component!: ComponentType<Component>;
@Input() props!: { [key: string]: unknown };
private closeSub!: Subscription;
constructor(
private contextMenuService: ContextMenuService,
) {}
ngOnInit()
{
this.closeSub = this.contextMenuService.afterClosed.subscribe(() => this.onMenuClosed());
const { props } = this;
const componentRef = this.contextMenuService.open({ x: <number>props.x, y: <number>props.y }, this.component);
for(const key in props) {
if(props.hasOwnProperty(key)) {
Object.defineProperty(componentRef.instance, key, {
get() { return props[key]; },
set(val) { props[key] = val; }
})
}
}
}
onMenuClosed()
{
this.closeSub.unsubscribe();
if(this.el)
this.el.remove();
}
}