Filter Throws Exception for Undefined Properties

Filter that throws exceptions for undefined properties

by Jeremy Likness

HTML

<div ng-app="myApp" ng-controller="myController">
    {{variable | throwUndefined}}
    {{variable1 | throwUndefined}}
</div>

JavaScript

(function () {
    var app = angular.module("myApp", []); 
    app.filter("throwUndefined", function ($exceptionHandler) {
        return function (input) {
            if (input === undefined) {
                $exceptionHandler(new Error("Property was undefined"),
                                  "throwUndefined filter");
            }
            return input;
        };
    });
    app.controller("myController", function ($scope) {
        $scope.variable = "This will display.";
    });
})();