0

I'm having a bit of trouble getting Angular ng-if to work. I want one of my DOM elements to disappear when $scope.week = 1.

In my controller I've set

$scope.week = 1

In my markup I have

<span class="prev" ng-if="{{week}} !== 1"></span>

Does anyone know how to get boolean conditionals to evaluate in ng-if? Thanks!

Roham Rafii
  • 2,929
  • 7
  • 35
  • 49

1 Answers1

2

Remove the {{ }} from week variable. Ng-if accesses scope objects without the braces.

<span class="prev" ng-if="week !== 1"></span>

See the documentation on ng-if for more examples.

Here is the jsfiddle, and a jsfiddle with a toggle function.

Gaʀʀʏ
  • 4,372
  • 3
  • 39
  • 59
  • thanks! I didn't catch the extra {{}} around my variable. It also turns out that I was on a version of angular that predates ng-if, so now I'm all good to go – user3786560 Jun 28 '14 at 21:58
  • Ahh, I forgot to mention the version issue. Good catch. Unrelated: Thank you for giving me `1337` reputation. – Gaʀʀʏ Jun 28 '14 at 22:03