Using mat-menu as context menu: How to close opened mat-menu, and open it in another location

37 views
Skip to first unread message

Ravjot Singh

unread,
Mar 4, 2020, 10:09:37 AM3/4/20
to angular-material2
This works fine but i am unable to open the contextmenu from new place. 
@Component({
  selector: 'fl-home',
  template:`
 <mat-menu #contextmenu>
      <div >
           <button mat-menu-item>Clear all Paths</button>
       </div>
  </mat-menu>
  <div [matMenuTriggerFor]="contextmenu" [style.position]="'absolute'" [style.left.px]="menuX" [style.top.px]="menuY" ></div>
  
  <div class="container" (contextmenu)="onTriggerContextMenu($event);"> ....</div>
`})
export class HomeComponent  {

    menuX:number=0
    menuY:number=0

    @ViewChild(MatMenuTrigger,{static:false}) menu: MatMenuTrigger; 
    
   
    onTriggerContextMenu(event){
        
        event.preventDefault();
        this.menuX = event.x - 10;
        this.menuY = event.y - 10;
        this.menu.closeMenu() // putting this does not work.
        this.menu.openMenu()

    }
}
Reply all
Reply to author
Forward
0 new messages