I have the p-table and this is what the structure looks like:
...
<p-tabPanel header="A">
<a *ngIf="importedNewCustomer.length; else ErrorPage">
<p-table
#CutsomerList
[value]="importedNewCustomer"
[scrollable]="true"
[(selection)]="selectedConfirmedNewCustomer"
>
<ng-template pTemplate="header" let-newCustomer>
<tr>
<th>
<p-tableHeaderCheckbox></p-tableHeaderCheckbox>
Select All
</th>
<th>Customer Name</th>
<th>Age</th>
<th>Phone Number</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-newCustomer>
<tr>
<td>
<p-tableCheckbox [value]="newCustomer"></p-tableCheckbox>
</td>
<td>{{ newCustomer.Name }}</td>
<td>{{ newCustomer.Age }}</td>
<td>{{ newCustomer.PhoneNumber }}</td>
</tr>
</ng-template>
</p-table>
</a>
<ng-template #ErrorPage>
<h1>No New Customer</h1>
</ng-template>
</p-tabPanel>
...
And this is importedNewCustomer
data
[
{
Name : "Jason",
Age : 29,
PhoneNumber: "111-222-3333",
Level: "Secured"
},
{
Name : "Smith",
Age : 56,
PhoneNumber: "222-333-4444",
Level: "Secured"
},
{
Name : "Jackson",
Age : 18,
PhoneNumber: "333-444-5555",
Level: "Secured"
}
]
This is the action I expect from users.
- Users drop down their files to import customer data.
- The imported data has all either "Secured" or "NotSecured" only.
- The above data has all "Secured".
- When clicking on the "import" button, I want to make the PhoneNumber column unshown(hidden) because the Level is "Secured".
This is my try:
.
.
.
<ng-template pTemplate="header" let-newCustomer>
<tr>
<th>
<p-tableHeaderCheckbox></p-tableHeaderCheckbox>
Select All
</th>
<th>Customer Name</th>
<th>Age</th>
<th *ngIf="newCustomer.Level === 'Secured'">Phone Number</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-newCustomer>
<tr>
<td>
<p-tableCheckbox [value]="newCustomer"></p-tableCheckbox>
</td>
<td>{{ newCustomer.Name }}</td>
<td>{{ newCustomer.Age }}</td>
<td *ngIf="newCustomer.Level === 'Secured'">{{ newCustomer.PhoneNumber }}</td>
</tr>
</ng-template>
.
.
.
However, when the user drops down the file and clicks on the "Import" button, they face this error in console:
ERROR TypeError: Cannot read properties of undefined (reading 'Level')
I don't understand the error because the Level
is defined clearly..
Any ideas, please?