0

I have the following code in my Angular2 Template:

<li>Gender: <span *ng-if="rating.isMale">Male</span><span *ng-if="!rating.isMale">Female</span></li>

Where rating.isMale is a boolean. But I get this error in the console:

EXCEPTION: Error: Uncaught (in promise): Template parse errors: Can't bind to 'ng-if' since it isn't a known native property ("ode}}

  • Age: {{rating.age}}
  • Gender: ]*ng-if="rating.isMale">MaleFemale
  • <"): RatingComponent@12:38 Property binding ng-if not used by any directive on an embedded template ("untryCode}}
  • Age: {{rating.age}}
  • Gender: [ERROR ->]MaleFemale
  • "): RatingComponent@12:32 Can't bind to 'ng-if' since it isn't a known native property (" {{rating.age}}
  • Gender: Male]*ng-if="!rating.isMale">Female
  • "): RatingComponent@12:78 Property binding ng-if not used by any directive on an embedded template ("i>Age: {{rating.age}}
  • Gender: Male[ERROR ->]Female
  • "): RatingComponent@12:72

    What is the correct way of accomplishing to write the two answers based on the boolean as I wish?

    Günter Zöchbauer
    • 623,577
    • 216
    • 2,003
    • 1,567
    Piddien
    • 1,436
    • 4
    • 18
    • 38

    1 Answers1

    5

    ng-if="boolean" is now *ngIf="boolean" in Angular2

    inoabrian
    • 3,762
    • 1
    • 19
    • 27