繁体   English   中英

配置注释错误:参数'fn'不是函数,得到字符串

[英]Configuration annotations error: Argument 'fn' is not a function, got string

除了一些文件之外,我在各地都使用了注释(在控制器,服务......中)。 当我遇到缩小问题时,我正在重写最后几个文件。

这是我目前的配置:

(function () {

    angular.module('app')
        .config(function ($stateProvider, $urlRouterProvider, $provide, $httpProvider, showErrorsConfigProvider, LightboxProvider) {
            $httpProvider.interceptors.push('requestsErrorHandler');
            $urlRouterProvider.otherwise('/');
            showErrorsConfigProvider.showSuccess(true);

            // more code
            // routing and stuff...


        });

}());

这很好用。 我现在正试图用注释重写这个:

(function () {

    angular.module('app')
        .config('configurationapp', configurationapp);

    configurationapp.$inject = ['$stateProvider', '$urlRouterProvider', '$provide', '$httpProvider', 'showErrorsConfigProvider', 'LightboxProvider'];

    function configurationapp($stateProvider, $urlRouterProvider, $provide, $httpProvider, showErrorsConfigProvider, LightboxProvider) {
            $httpProvider.interceptors.push('requestsErrorHandler');
            $urlRouterProvider.otherwise('/');
            showErrorsConfigProvider.showSuccess(true);


            // more code
            // routing and stuff


        }
}());

但是,我收到此错误:

Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [ng:areq] Argument 'fn' is not a function, got string

我不明白为什么我会收到这个错误。 我完成了与所有其他文件完全相同的操作,但这仍然不起作用。

我究竟做错了什么?

提供了一个字符串来config

angular.module('app')
    .config('configurationapp', configurationapp);

它需要一个参数,函数或数组。 configurationapp不是Angular服务,不应该命名:

angular.module('app')
    .config(configurationapp);

试试这个语法。 我发现内联注释比显式注入依赖项更容易:

  (function () {

    angular.module('app')
        .config(['$stateProvider', '$urlRouterProvider', '$provide', '$httpProvider', 'showErrorsConfigProvider', 'LightboxProvider',
        function ($stateProvider, $urlRouterProvider, $provide, $httpProvider, showErrorsConfigProvider, LightboxProvider) {
            $httpProvider.interceptors.push('requestsErrorHandler');
            $urlRouterProvider.otherwise('/');
            showErrorsConfigProvider.showSuccess(true);

            // more code
            // routing and stuff...


        }]);

}());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM