7

I am showing list of opportunity in a Lightning component. And I want to display them if the opportunity list size > 0 . i.e here ( opportunityList > 0)

<lightning:select name="selectOpportunity" label="" required="false">
            <aura:iteration items="{!v.opportunityList}" var="opp">
                <option value="{!opp.Id}" text="{!opp.Name}"></option>
            </aura:iteration>
</lightning:select>
0

1 Answer 1

26

There's a handful of ways, but the most robust would probably be to see if it's not(empty(...)):

<aura:if isTrue="{!not(empty(v.opportunityList))}"> ...

This will suppress rendering if the list is empty, or null, or undefined...

6
  • 2
    I was going to suggest .length > 0 but this is much better Commented Jun 4, 2018 at 17:38
  • Great !! it works Commented Jun 4, 2018 at 17:41
  • @Sebastian Kessel , what is the other way? Commented Jun 4, 2018 at 17:41
  • {!v.opportunityList.length &gt; 0} but I would go with the suggested solution. It is much better, because it accounts for null/undefined. Commented Jun 4, 2018 at 17:42
  • 1
    @cookie Objects don't have a length, but we can get the length of an Array (List) or String.
    – sfdcfox
    Commented Nov 12, 2018 at 6:03

You must log in to answer this question.

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