Salesforce Lightning: Setting a conditional default value blocks any further changes to the attribute. Including object will allow changes but only from the object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component implements="flexipage:availableForAllPageTypes"> | |
<!-- Simple example of conditional default blocking changes --> | |
<aura:attribute name="myString" type="string" default="{!if(false, 'Default Val', 'Other Default')}"/> | |
<aura:attribute name="mySimpleString" type="string" default="Default Val"/> | |
<!-- Conditional default on object value will update, but will not allow external changes --> | |
<aura:attribute name="myObj" type="object"/> | |
<aura:attribute name="myObjString" type="string" default="{!if(empty(v.myObj), 'Default Val', v.myObj.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 --> | |
{!v.myObjString} <!-- Will be changed to the value of v.myObj.val when it changes --> | |
</div> | |
</aura:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
doInit : function(component, event, helper) { | |
component.set('v.myString', 'Set Directly'); | |
component.set('v.mySimpleString', 'Set Directly'); | |
component.set('v.myObj', {val: 'Set in Object'}); | |
component.set('v.myObjString', 'Set Directly'); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment