1

I am trying to format the option text based on certain condition. I have tried several ways but doesn't seem to be working. For a workaround I could use jquery and populate the option list based on condition but trying to do it without adding more code. Any help would be appreciated. Thanks in advance.

<option value="fooditem_size1">{{selectedFoodItem.fooditem_size1_name}} 
  <span ng-if="selectedFoodItem.fooditem_size1_price > 0"> + 
       ${{selectedFoodItem.fooditem_size1_price}}
  </span>
</option>
georgeawg
  • 48,608
  • 13
  • 72
  • 95
vivek modi
  • 13
  • 3
  • It should work. Look here https://stackoverflow.com/questions/33926520 and https://stackoverflow.com/questions/15810278 – Chris Happy Jun 11 '19 at 04:12

1 Answers1

1

Use a ternary operator:

<option value="fooditem_size1">
    {{selectedFoodItem.fooditem_size1_name + 
        (selectedFoodItem.fooditem_size1_price > 0) ? 
          ( ' + $' + selectedFoodItem.fooditem_size1_price ) : "" }}
</option>

The only permitted content of an <option> element is text, possibly with escaped characters (like &eacute;).

For more information, see

georgeawg
  • 48,608
  • 13
  • 72
  • 95