Search code examples
angularjsangular-ng-ifng-hide

Hide element depending on value json in Angularjs


I want to hide a div depending on the value I have in the json

for example I have this {{product.currency}} and the value can be: £ or € if the value is equal € I want to hide this element.


Solution

  • fairly simple with ng-hide or the opposite ng-show or to not have it in page use ng-if

    <div ng-hide="product.currency =='€'" >
     <!-- or -->
    <div ng-show="product.currency !='€'" >
     <!-- or -->
    <div ng-if="product.currency !='€'" > 
    

    And one more alternative, not as elegant or efficient is ng-switch.

    It is well worth spending a bit of time looking through all the core directives shown in menu on left side of API reference docs.