AngularJS:缩小后出错

时间:2015-02-10 14:40:44

标签: javascript angularjs dependency-injection

在缩小我的AngularJS应用程序后,我收到此错误:

  

n未使用显式注释,无法在严格中调用   模式

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

(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函数也必须注释?我该怎么办?

1 个答案:

答案 0 :(得分:2)

您还需要将$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'];