AngularJS: 缩小后出错

AngularJS: Error after minify

缩小我的 AngularJS 应用程序后,出现此错误:

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

我认为它来自这个装饰器:

(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]);
}());

可能是因为logDecorator函数也要注解?我应该怎么做?

您还需要提供将 $delegate 服务缩小到 logDecorator 函数的安全注入。尝试以下两个选项。

选项#1:

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

选项#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'];