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

Sebastian Barth picture Sebastian Barth · Nov 20, 2014 · Viewed 146.3k times · Source

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>

Answer

jlewkovich picture jlewkovich · May 2, 2015

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!