加载模块失败.处理步骤

Failed to load modules

本文关键字:处理 失败 模块 加载      更新时间:2023-09-26

你好,我正在尝试开发一个web应用程序与angular。我已经添加了ng-app="appApp"到html文件和。js文件。

main.controller.js

(function () {
'use strict';
// register the controller as MainController
angular
    .module('appApp.main')
    .controller('MainController', MainController);
/**
 * @ngdoc function
 * @name appApp.main.provider:MainController
 * @description
 * Provider of the {@link appApp.main.controller:MainController MainController}
 *
 * @param {Service} $scope The scope service to use
 * @param {Service} $http The http service to use
 */
// MainController.$inject = [];
function MainController() {
    var vm = this;
}
})();

main.js

(function () {
'use strict';
// register the route config on the application
angular
    .module('appApp.main', ['ui.router'])
    .config(configMainRoute)
// inject configMainRoute dependencies
configMainRoute.$inject = ['$stateProvider', 'mainMenuProvider'];
// route config function configuring the passed $stateProvider
function configMainRoute($stateProvider, mainMenuProvider) {
    var mainState = {
        name: 'main',
        url: '/',
        authenticate: true,
        templateUrl: 'app/main/main.html',
        controller: 'MainController',
        controllerAs: 'vm'
    };
    $stateProvider.state(mainState);
    mainMenuProvider.addMenuItem({
        name: 'Home',
        state: mainState.name,
        order: 1
    });
}
})();

app.js

(function () {
'use strict';
angular
    .module('appApp', [
        // Add modules below
        'ngCookies',
        'ngResource',
        'ngSanitize',
        'ngMessages',
        'ngMaterial',
        'ui.router',
        'btford.socket-io',
        'appApp.main'
    ])
    .config(appConfig)
    .run(appRun);

...........

当我运行应用程序时,我得到这个错误:

  1. 错误:[ng:areq]参数'MainController'不是一个函数,得到未定义
  2. 未捕获的错误:[$injector:nomod]模块的appApp。主服务器不可用!您要么拼错了模块名,要么忘记加载它。如果注册一个模块,请确保将依赖项指定为第二个参数。

如何修复这个错误?谢谢你

第一件事是:

在html中你已经写了

ng-app="appApp"

但是在模块定义中你写了

angular
.module('appApp.main', ['ui.router'])

模块名应该是相同的,除非你有另一个appApp模块,并且你添加了"appApp。Main"模块作为依赖项。

另一件事是,当你使用"ui-router"时,你需要在html中链接ui-router的js库文件和angular库文件。

检查js文件的顺序。首先是angular,然后是所有库js,然后是app, main, main controller

我想,

1。你应该调用ng-app="appApp。主要

2。你应该首先声明appApp模块。你应该替换main.js

中的一些代码
angular.module('appApp.main', []);
angular.module('appApp', [
        'ui.router',
        'appApp.main'
    ])...

同时,删除[ui]。在main.js中。它已在app.js

中声明