I am able to do the conditional rendering on visualforce page
visualforce page:
<table id="tblContact">
<thead>
<tr>
<td>Name</td>
<td>Email</td>
<td>Phone</td>
<td>Type</td>
<td>Profile ID</td>
</tr>
</thead>
<tbody>
<apex:repeat id="repeatContact" var="dt" value="{!contactList}">
<tr id="datarow">
<td>{!dt.Account.Name}</td>
<td>{!dt.Email}</td>
<td>{!dt.Phone}</td>
<td>{!dt.Type} {!If((dt.subType!=null), ' - ' + dt.subType, '')}</td>
<td>{!If((dt.IsPersonAccount), 'Customer', dt.RecordType_Name__c)}</td>
</tr>
</apex:repeat>
</tbody>
</table>
but in the LWC, I am not able to do this conditional rendering
Here is the detail of my LWC html file:
LWC.html
<template>
<lightning-card title="Contact" icon-name="action:new_task">
<div class="slds-m-around_medium">
<template if:true={contactList.data}>
<table id="tblContactList">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Type</th>
<th>Profile ID</th>
</tr>
</thead>
<tbody>
<template for:each={contactList.data} for:item="dt" for:index="indexvar">
<tr id="datarow">
<td>{!dt.Account.Name}</td>
<td>{!dt.Email}</td>
<td>{!dt.Phone}</td>
<!-- How to do conditional redering on these fields in LWC? -->
<td>{!dt.Type} {!If((dt.subType!=null), ' - ' + dt.subType, '')}</td>
<td>{!If((dt.IsPersonAccount), 'Customer', dt.RecordType_Name__c)}</td>
</tr>
</template>
</tbody>
</table>
</template>
<template if:true={contactList.error}>
{contactList.error}
</template>
</div>
</lightning-card>
</template>
the error I got when trying to do conditional rendering in LWC:
LWC1060: Template expression doesn't allow UnaryExpression
Basically I want to print the table data based on each record condition in the table. How can I achieve this in LWC?
EDIT
My question is not related to createComponent
or createElement
. This is about displaying the data using expression function (similar using {!if(condition, true, false))}
in visualforce page). I cannot achieve this expression function in LWC
createElement
orcreateComponent
at all