Tuesday, July 30, 2019

How to Unescape HTML in Lightning Component

Use  <aura:unescapedHtml /> component to unescape the HTML in Lightning Component.


Example

Lightning Component
<aura:component implements="flexipage:availableForAllPageTypes">
    <aura:attribute name="strURL" type="String" />
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <lightning:card>
        <p class="slds-m-around--xx-large">
            <h2>Welcome to my <aura:unescapedHtml value="{!v.strURL}"/></h2>
        </p>
    </lightning:card>
</aura:component>
JS Controller
({
     doInit : function(component, event, helper) {
        let strURL = '<a href="https://www.salesforcecodecrack.com/" target="_blank">Salesforce Code Crack</a> Blog.';
        component.set('v.strURL', strURL); 
     }
})
Resource
aura:unescapedHtml

1 comment:

  1. can we use lightning:formattedRichText tag instead of aura:unescapedHtml

    ReplyDelete