angularjsangularjs-ng-show

How to check if a scope variable is undefined in AngularJS template?


How to check if a scope variable is undefined?

This does not work:

<p ng-show="foo == undefined">Show this if $scope.foo == undefined</p>

Solution

  • Here is the cleanest way to do this:

    <p ng-show="{{foo === undefined}}">Show this if $scope.foo === undefined</p>
    

    No need to create a helper function in the controller!