In this blog we are going to learn about aura:unescapedHtml in lightning component. This component is used to write the html content as it is without performing recalculation. Means it does not filter the value which is assigned to it. It has two attributes.

  1. Body  : It won’t be rendered
  2. value : It is of string type.

Note :

–> To avoid xss vulnerability you must sanitise value which you are going to assign this component.
Let’s see an example :

 

Example

In this example we are going to render a coloured span.
# Lightning Component

<aura:component >
 <!-- 
 /**
 * Webkul Software.
 *
 * @category Webkul
 * @author Webkul
 * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https://webkul.com)
 * @license https://store.webkul.com/license.html
 */
 -->
 <aura:attribute name="cval" type="String"/>
 <aura:handler name="init" value="{!this}" action="{!c.myAction}" />
 <div>
 This value is rendered by using aura:unescapedHtml : <aura:unescapedHtml value="{!v.cval}" />
 This value is rendered by span : <span>{!v.cval}</span>
 </div>
</aura:component>

Now let’s set the value of aura:unescapedHtml by using controller.

# Controller

({
	myAction : function(component, event, helper) {
		component.set("v.cval", "<span class='hello'>Hello World!!</span>");
	}
})

 

Output

unescapedHtml

Support

That’s all for aura:unescapedHtml in lightning component , still if you have any further query or seek assistance to make your salesforce classic apps compatible with lightning experience, feel free to contact us, we will be happy to help you https://wedgecommerce.com/contact-us/.

Leave A Reply

Please verify that you are not a robot.

Tell us about Your Company

How can we help you with your business?




    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home