引导更改后angularjs升级未知提供程序

z9gpfhce  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(190)

我正在尝试将大型angular.js应用程序(1.5.9)升级到angular的最新版本。
我正在将该应用程序转变为angularjs/angular混合应用程序,并在指南中达到了这一步:
https://angular.io/guide/upgrade#bootstrapping-混合应用
到目前为止,我已经从使用gulp改为Webpack4,该应用程序的工作原理与以前相同。
我遇到的问题是,当我从在index.html中使用ng app指令切换到在javascript中使用引导时,应用无法启动,引发以下错误:
未捕获错误:[$injector:unpr]未知提供程序:stateserviceprovider<-stateservice
这是来自我的app.js文件,如下所示:

angular.module('app-engine', [
    'app-engine.state',
    'app-engine.api',
    // other modules
])
.factory('bestInterceptor', bestInterceptor)
// other configs which aren't throwing Unknown provider errors
.run(startUp);

bestInterceptor.$inject = ['StateBootstrappingService'];

function bestInterceptor(StateBootstrappingService) {
    return {
        request: config => {
            if (!StateBootstrappingService.isBestSsoOn()) {
                config.headers['x-impersonated-user'] = StateBootstrappingService.getUserName();
            }
            return config;
        }
    };
}

startUp.$inject = ['$rootScope', '$state', '$timeout', 'StateService']

function startUp($rootScope, $state, $timeout, StateService) {
    // start up code
}

有一个单独的app.modules.js文件,用于定义应用程序中的其他模块。
包括:

angular.module('app-engine.state', ['rx', 'app-engine.api']);

未知提供程序错误中提到的服务如下所示:

(function() {
    'use strict';
    angular
        .module('app-engine.state')
        .factory('StateService', StateService);

    StateService.$inject = [
        '$state',
        '$log',
        'rx',
        // a few other services that exist in the app
    ];

    function StateService(
         // all the above in $inject
    ) {
         // service code
    }
})();

正如指南所指示的,我正在从index.html中删除ng app=“app engine”,并将其添加到javascript中。我在app.modules.js文件的底部添加了它。

angular.bootstrap(document.body, ['app-engine']);

此更改之后是引发未知提供程序错误时。我已经确认源代码是app.js中的启动函数。我已经尝试将应用程序中的所有模块都包含在“应用程序引擎”所需的数组中,但没有改变任何内容。有趣的是,bestinterceptor函数没有抛出任何错误,尽管也使用了服务(statebootstrappingservice的设置方式与stateservice相同)。
有什么明显的我做错了吗?或者有人知道如何解决这个问题吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题