Skip to content

Instantly share code, notes, and snippets.

@danic85
Last active June 14, 2018 10:28
Show Gist options
  • Save danic85/c5c7f9164a5916d2a2f76991bba61e94 to your computer and use it in GitHub Desktop.
Save danic85/c5c7f9164a5916d2a2f76991bba61e94 to your computer and use it in GitHub Desktop.
Salesforce Lightning: Setting a conditional default value blocks any further changes to the attribute.
<aura:component implements="flexipage:availableForAllPageTypes">
<aura:attribute name="myString" type="string" default="{!if(false, 'Default Val', 'Other Default')}"/>
<aura:attribute name="mySimpleString" type="string" default="Default Val"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<div class="slds-card">
{!v.myString} <!-- Will always output 'Other Default', even if changed later by doInit -->
{!v.mySimpleString} <!-- Will be changed to 'Set Directly' by doInit -->
</div>
</aura:component>
({
doInit : function(component, event, helper) {
component.set('v.myString', 'Set Directly');
component.set('v.mySimpleString', 'Set Directly');
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment