13

I´m trying to use the attribute appendTo in the component ContextMenu, but I want attach the behavior to one element, like a div.

Deilan
  • 4,740
  • 3
  • 39
  • 52
Jhonatan Delgado
  • 131
  • 1
  • 1
  • 4

3 Answers3

15

on the element u want to append to add a hashtag #myHashTag and on the prime element u want to append add: [appendTo]="myHashTag" <- without the # sign

example:

<div class="recording-control-button" #stopbutton></div>

<p-confirmDialog [appendTo]="stopbutton"></p-confirmDialog>
asafrob
  • 1,838
  • 13
  • 16
  • 3
    I'm doing the same with a sidebar component, but no matter what element I attach it to, it still takes up the whole space/height on the left of the screen :-( – AsGoodAsItGets Oct 05 '18 at 10:19
  • This solution worked with Angular 12 and PrimeNG 12 today. – Mycah Sep 13 '21 at 18:05
0

I'm presuming you're using Angular 2?

Based on the information on the api for primeng context menu here:

PrimeNg context menu

You need to use a Angular 2 template variable, see here:

Angular 2 HTML variables

Mark
  • 44
  • 4
0

I try this and it works - [appendTo]="'body or template or any Id'"

For example: <div #largeModal></div> - define anywhere in html, but in your project

Define this menu primeng in your html <ng-template let-item="rowData" <p-menu #menu popup="popup" [model]="items"></p-menu> <button type="button" pButton icon="fa fa-list" label="Show" [appendTo]="'largeModal'" (click)="menu.toggle($event)"></button> </ng-template>

Amitesh Singh
  • 162
  • 2
  • 7