I am experiencing something strange, but I suspect I am doing something wrong
I have two string aura:attributes
. When I try to compare them, the comparison doesn't work. Here is an example
Component
<aura:component description="BookATourButtons">
<aura:attribute type="String" name="stepNumber"/>
<aura:attribute type="String" name="maxSteps"/>
<aura:registerEvent name="doNavigation" type="c:BookATourBeforeNavigate"/>
{!v.stepNumber} -- {!v.maxSteps}
equals : {!v.stepNumber == v.maxSteps}
</aura:component>
Usage
Parameters are being passed from parent component:
<c:BookATourButtons stepNumber="{!v.stepNumber}" maxSteps="{!v.maxStepNumber}"/>
Examples
If I pass the number '1' on both parameters, the output is
1 — 1 equals : false
If I change the second expression to {!v.stepNumber == '1'}
, then I correctly get
1 — 1 equals : true
Changing the calling param to <c:BookATourButtons stepNumber="{!v.stepNumber}" maxSteps="1"/>
also works
1 — 1 equals : true
I suspect the comparison fails because both strings are treated like objects, but I can't figure out how to get around that.
PS: I've tried using other operators like equals
and eq
.
Best Answer
This might not be the answer, but would help us determine the behaviour.
I tried your code, and defaulted both attributes as String.
Case 1:
The OP:
Case 2: I converted stepNumber as Integer or Decimal
The output :
Based on this behaviour, we can deduce that datatype of stepNumberis changed in between.