The documentation shows the following example to input HTML with styling:
var rte = "<h1 style=\"color:blue;\">This is a blue heading</h1>";
cmp.set("v.richtext", rte);
This works, but if you try to give <h1 style="color:blue;">This is a blue heading</h1>
from an Apex controller, the styling is disregarded and the color is no longer blue but the default.
Can anyone reproduce the error or am I missing something? I cannot add any style attributes to my html tags.
Component:
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" controller="EmailController" >
<aura:handler name="init" action="{! c.doInit}" value="{! this }" />
<aura:attribute name="html" type="String" />
<aura:attribute name="inputRichTextFormats" type="String" default="[
'font', 'size', 'bold', 'italic', 'underline',
'strike', 'list', 'indent', 'align',
'clean', 'table', 'header']"/>
<lightning:inputRichText value="{!v.html}" formats="{! v.inputRichTextFormats }" />
</aura:component>
JS Controller:
({
doInit : function(component, event, helper) {
helper.callApexMethod(component, 'getHTML', false, function(response) {
let state = response.getState();
if (state === "SUCCESS") {
var htmlresponse = response.getReturnValue();
component.set('v.html', htmlresponse);
} else {
console.log("Failed with state: " + state);
}
});
}
})
Helper:
({
callApexMethod: function(component, method, params, callback) {
let action = component.get("c." + method);
if (params) action.setParams(params);
if (callback) action.setCallback(this, callback);
$A.enqueueAction(action);
}
})
Apex Controller:
public class EmailController{
@AuraEnabled
public static String getHTML(){
return '<h1 style="color:blue;">This is a blue heading</h1>';
}
}