Search code examples
jsonangularionic-frameworkangular-ng-if

Use *ngIf with JSON


I'm creating an Ionic app using a JSON file. Everything is ok for the moment, just when I want to use ngIf and JSON. I don't know how to use it... for example I want to do this :

<p *ngIf="{{item.price }}  == 1"> Okey </p>
<p> *ngIf="{{item.price}}  == 2"> Okey2 </p>

And in the json file if the value of the price is 1 it'll show "Okey".

I hope you understood me. Thank you


Solution

  • Don't use the brackets in the *ngIf-Statement.

    <p *ngIf="item.price == 1"> Okey </p>
    <p *ngIf="item.price == 2"> Okey2 </p>