p-contextMenu not allowing *ngIf for showing context menu

UI Components for Angular
Post Reply
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.

Posts: 93
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.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests