Search code examples
javascriptangularjsangular-ng-if

angular ng-if numerical boolean


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!


Solution

  • 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.