Skip to content

Instantly share code, notes, and snippets.

@itsmebasti
Last active February 6, 2018 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsmebasti/1088f49e96e0ce57d18bea61465fa9bf to your computer and use it in GitHub Desktop.
Save itsmebasti/1088f49e96e0ce57d18bea61465fa9bf to your computer and use it in GitHub Desktop.
Reference Change Handlers in Lightning
<aura:application extends="force:slds">
<c:referenceTest />
</aura:application>
<aura:component >
<aura:attribute name="value1" type="Decimal" />
<aura:attribute name="value2" type="Decimal" />
<aura:attribute name="valueList" type="Decimal[]" />
<aura:attribute name="referencedList" type="Decimal[]" />
<aura:attribute name="listWithReferences" type="Decimal[]" />
<aura:handler name="init" value="{!this}" action="{!c.initialize}" />
<aura:handler name="change" value="{!v.value1}" action="{!c.printEventExpression}" />
<aura:handler name="change" value="{!v.value2}" action="{!c.printEventExpression}" />
<aura:handler name="change" value="{!v.valueList}" action="{!c.printEventExpression}" />
<aura:handler name="change" value="{!v.referencedList}" action="{!c.printEventExpression}" />
<aura:handler name="change" value="{!v.listWithReferences}" action="{!c.printEventExpression}" />
<lightning:input aura:id="input" value="{!v.value1}" type="number" variant="label-hidden" label="Value" />
<lightning:input aura:id="input" value="{!v.value2}" type="number" variant="label-hidden" label="Value" />
</aura:component>
({
initialize: function(cmp, evt, helper) {
var values = [1,2];
cmp.set("v.valueList", values);
cmp.set("v.value1", cmp.getReference("v.valueList.0"));
cmp.set("v.value2", cmp.getReference("v.valueList.1"));
cmp.set("v.referencedList", cmp.getReference("v.valueList"));
cmp.set("v.listWithReferences", [cmp.getReference("v.valueList.0"),
cmp.getReference("v.valueList.1")]);
},
printEventExpression: function(cmp, evt, helper) {
console.log(evt.getParam("expression"));
},
})
@itsmebasti
Copy link
Author

Output:

v.valueList.1
v.referencedList
v.value2
v.value2

listWithReferences seems not to fire a change event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment