p-contextMenu not allowing *ngIf for showing context menu

UI Components for Angular
Post Reply
jgthompson
Posts: 1
Joined: 20 Feb 2018, 16:41

20 Feb 2018, 16:52

I have a data table that I have a context menu defined:
<p-table #table [value]="sites" [rows]="25" [paginator]="true" [pageLinks]="5" [rowsPerPageOptions]="[5, 10, 25, 50, 100, 250]"
[globalFilterFields]="['name', 'fullAddress', 'country']" [loading]="loading" loadingIcon="fa-spinner" [scrollable]="true" scrollHeight="600px" [responsive]="true"
[(contextMenuSelection)]="selectedSite" [contextMenu]="cm" [(selection)]="selectedSites" selectionMode="multiple">

And the p-contextMenu:

<p-contextMenu #cm [model]="items"></p-contextMenu>

I want to only allow the menu to be shown when rows are selected in the p-table. E.g.

<p-contextMenu *ngIf="selectedSites.length > 0" #cm [model]="items"></p-contextMenu>

But if I do this I get compilation error:

Property 'cm' does not exist on type 'GroupSummaryComponent'.

I've seen post that say this should work.

paulswan
Posts: 94
Joined: 27 Apr 2017, 08:19

22 Feb 2018, 22:55

You get that error because the *ngIf condition will be false when your component loads. Therefor the variable #cm will not exist at this time.

gopalakrishnach
Posts: 18
Joined: 19 Apr 2017, 23:28

12 Apr 2018, 19:20

I also need this. I need to show context menu only for 2 columns out of 10 columns in my p-datatable. But contextmenu is shown for all columns.

gopalakrishnach
Posts: 18
Joined: 19 Apr 2017, 23:28

12 Apr 2018, 19:21

I also need this. I need to show context menu only for 2 columns out of 10 columns in my p-datatable. But contextmenu is shown for all columns.

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 10 guests