Angular.js expression exception exception

Is it possible to configure this?

From here , the expressions are excusable, but I would like to know what my mistake is.

Parting. In JavaScript, when trying to evaluate undefined properties, a ReferenceError or TypeError is thrown. In Angular, evaluating expressions forgives undefined and null.

+4
source share
1 answer

Actually there

In Angular, the $ interpolation service is responsible for working with the binding expression, since this service is forgiving, you do not see any errors. However, you can create a wrapper for it that tells you when the result of the falsity is created.

Below is the code from http://odetocode.com/ See this blog post

app.config(function($provide){
    $provide.decorator("$interpolate", function($delegate){

        var interpolateWrap = function(){
            var interpolationFn = $delegate.apply(this, arguments);
            if(interpolationFn) {
                return interpolationFnWrap(interpolationFn, arguments);
            }
        };

        var interpolationFnWrap = function(interpolationFn, interpolationArgs){
            return function(){
                var result = interpolationFn.apply(this, arguments);
                var log = result ? console.log : console.warn;
                log.call(console, "interpolation of  " + interpolationArgs[0].trim(), 
                                  ":", result.trim());
                return result;
            };
        };

        angular.extend(interpolateWrap, $delegate);
        return interpolateWrap;

    });
});
+1

Source: https://habr.com/ru/post/1541828/


All Articles