Angular ng-switch with boolean

Isuru picture Isuru · Dec 9, 2013 · Viewed 25.4k times · Source

I want to check boolean data with angular ng-switch

this is my code. but it is not working

<div ng-switch={{Item.ItemDetails.IsNew}}>
    <div ng-switch-when="true">
         <p class="new fontsize9 fontWeightBold">NEW</p>
    </div>
 </div>
    <div ng-switch={{Item.ItemDetails.IsFeatured}}>
         <div ng-switch-when="true">
               <div class="featured">
                    <p class="fontWeightBold fontsize8">featured</p>
               </div>
         </div>
     </div>

values of {{Item.ItemDetails.IsNew}} and {{Item.ItemDetails.IsFeatured}} are true or false

Answer

bruceczk picture bruceczk · Jan 6, 2015

Convert the boolean to a string:

<div ng-switch="Item.ItemDetails.IsNew.toString()">
    <div ng-switch-when="true">