3

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.

0

1 Answer 1

2

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:

<aura:application >
    <aura:attribute type="String" name="stepNumber" default="1"/>
    <aura:attribute type="String" name="maxSteps" default="1"/>



    {!v.stepNumber} -- {!v.maxSteps}
    equals : {!v.stepNumber == v.maxSteps}
    <hr></hr>
    {!v.stepNumber == '1'}
</aura:application>

The OP:

1 -- 1 equals : true
--------------------------------
true

Case 2: I converted stepNumber as Integer or Decimal

<aura:application >
    <aura:attribute type="Integer" name="stepNumber" default="1"/>
    <aura:attribute type="String" name="maxSteps" default="1"/>



    {!v.stepNumber} -- {!v.maxSteps}
    equals : {!v.stepNumber == v.maxSteps}
    <hr></hr>
    {!v.stepNumber == '1'}
</aura:application>

The output :

1 -- 1 equals : false
---------------------
false

Based on this behaviour, we can deduce that datatype of stepNumberis changed in between.

1
  • 1
    It's not exactly what I did, but this helped me figure out that the problem was in the datatype coming from the database. May 9, 2018 at 18:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .