Looking to use an Aura Attribute length value for a Lightning Accordion Section. Pretty basic but i can not figure out how to do the length value minus 2 within the label. I'd like to keep it as simple as possible but could certainly use the controller and an additional attribute but was wondering if there is anyway to do simple math in a dynamic label

label="{! con.policyOwner + ' (' + con.data.length + ')'}">

Yes, there's at least two ways you can do this:

label="{! con.policyOwner + ' (' + sub(con.data.length, 2) + ')'}">

sub(x, y) subtracts y from x and returns the result.

label="{! con.policyOwner + ' (' + (con.data.length - 2) + ')'}">

To avoid confusion in the parser, use parentheses to group the math operation.

You can see other functions and operators that you can use in expressions in the documentation.

  • Awesome, thank you. I had tried to use the -2 but did not use the parentheses correclty. Great stuff
    – Bobbygllh
    Mar 29 '19 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.