+ Start a Discussion
Luciano RobertoLuciano Roberto 

How pass value from controller to view in tag <h2>

Folks,

I'm configuring a toast and I need to pass the controller's text to the <h2> tag of the view of the lightning component

TestAlert.cmp

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,lightning:actionOverride,lightning:backgroundUtilityItem" access="GLOBAL" controller="AlertController">   

<aura:attribute name="Alert" type="Alert__c" default="{'sobjectType': 'Alert__c',
                         'Tipo_de_Alerta__c': '',
                         'Name': '',
                         'Alerta1__c': ''
                          }"/>
    
    
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
<div class="demo-only" style="height: 4rem;">
	<div class="slds-notify_container slds-is-relative">    
		<div aura:id="alerta" role="status"> 
			<div  class="slds-notify__content">
                
<h2 class="slds-text-heading_small ">	Alert message here		</h2>
    
<lightning:buttonIcon iconName="utility:close" variant="bare" alternativeText="Close"
 iconClass="{!v.type == 'warning' ? 'light' : 'dark'}" size="small"
 class="slds-button slds-button_icon slds-notify__close slds-button_icon-inverse"
 onclick="{!c.close}"/>      
    
			</div>
		</div>
	</div>
</div>

    
</aura:component>

Controller.js
doInit : function(component, event, helper)
    {

          
  var tipoAlerta = component.find( "alerta" );
        
  $A.util.addClass( tipoAlerta, "slds-notify" );
  $A.util.addClass( tipoAlerta, "slds-notify_toast" );      
  $A.util.addClass( tipoAlerta, "slds-theme_success" );    


//Code to pass text to view in tag <h2> </h2>
}
Best Answer chosen by Luciano Roberto
Raj VakatiRaj Vakati
Change it to 
 
<aura:unescapedHtml value="{!v.html}" />

 

All Answers

Raj VakatiRaj Vakati
You can do one thing .. 

1. Set the Controller HTML code into one of the attributes 
2. Render the value in UI using the aura:unesapeHTML code 
 
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,lightning:actionOverride,lightning:backgroundUtilityItem" access="GLOBAL" controller="AlertController">   

<aura:attribute name="html" type="String" >

<aura:attribute name="Alert" type="Alert__c" default="{'sobjectType': 'Alert__c',
                         'Tipo_de_Alerta__c': '',
                         'Name': '',
                         'Alerta1__c': ''
                          }"/>
    
    
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
	
	<aura:html>
	
	{!v.html}
	
	</aura:html>
	
	
<div class="demo-only" style="height: 4rem;">
	<div class="slds-notify_container slds-is-relative">    
		<div aura:id="alerta" role="status"> 
			<div  class="slds-notify__content">
                
<h2 class="slds-text-heading_small ">	Alert message here		</h2>
    
<lightning:buttonIcon iconName="utility:close" variant="bare" alternativeText="Close"
 iconClass="{!v.type == 'warning' ? 'light' : 'dark'}" size="small"
 class="slds-button slds-button_icon slds-notify__close slds-button_icon-inverse"
 onclick="{!c.close}"/>      
    
			</div>
		</div>
	</div>
</div>

    
</aura:component>
 
doInit : function(component, event, helper)
    {

          
  var tipoAlerta = component.find( "alerta" );
        
  $A.util.addClass( tipoAlerta, "slds-notify" );
  $A.util.addClass( tipoAlerta, "slds-notify_toast" );      
  $A.util.addClass( tipoAlerta, "slds-theme_success" );    

component.set("v.html","<h2>demo</h2>"):

//Code to pass text to view in tag <h2> </h2>
}

 
Luciano RobertoLuciano Roberto

Thanks Raj, but you are experiencing an error

 

User-added image

Raj VakatiRaj Vakati
Change it to 
 
<aura:unescapedHtml value="{!v.html}" />

 
This was selected as the best answer
Luciano RobertoLuciano Roberto
Perfect!!!
Tanks so mutch