1

After minifying my AngularJS app, I'm getting this error:

n is not using explicit annotation and cannot be invoked in strict mode

I think it comes from this decorator:

(function () {


    function logDecoratorConfig($provide) {
        $provide.decorator('$log', logDecorator);
    }

    function logDecorator($delegate) {

        $delegate.debug = function (msg) {
            var time = new Date().toString();
            console.log(time + " : " + msg);
        };

        return $delegate;
    }

    angular.module('services')
        .config(['$provide', logDecoratorConfig]);
}());

Maybe it is because the logDecorator function has to be annotated too? How should I do it?

1 Answer 1

2

You also need to provide minification safe injection of the $delegate service into logDecorator function. Try below two options.

Option #1:

function logDecoratorConfig($provide) {
    $provide.decorator('$log', ['$delegate', logDecorator]);
}

Option #2:

function logDecoratorConfig($provide) {
    $provide.decorator('$log', logDecorator);
}

function logDecorator($delegate) {

    $delegate.debug = function (msg) {
        var time = new Date().toString();
        console.log(time + " : " + msg);
    };

    return $delegate;
}

logDecorator.$inject = ['$delegate'];
Sign up to request clarification or add additional context in comments.

3 Comments

After applying those options the error still exists, so I think the problem is that the logDecorator function has to be annotated. How can I do that?
Above options both provide explicit annotation. If the error persists it means that there are another place that needs to be annotated.
Thanks, @dfsq. You were right. there was another place with the same issue.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.