加载模块失败.处理步骤
Failed to load modules
你好,我正在尝试开发一个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);
...........
当我运行应用程序时,我得到这个错误:
- 错误:[ng:areq]参数'MainController'不是一个函数,得到未定义
- 未捕获的错误:[$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
相关文章:
- Html<输入模式>使用JavaScript处理-超过时失败
- 移动优先 - 加密缓存成功和失败处理程序
- 当表单验证失败时,我将如何最好地处理下一个事件
- 处理 HTTP 请求失败
- 处理从 CDN 加载资源失败或缓慢的问题
- RequireJS:如何处理传递依赖项失败
- rsvp.js 如何处理被拒绝的承诺和失败回调链
- 在 RequireJS 中处理先决条件加载失败需要功能
- 如何使用 Q 和 JS 捕获或失败来处理错误
- 对折线进行动画处理失败,并显示经度/经度数组
- 在导航中对活动项目背景进行动画处理失败
- 为什么 Mocha 在报告者处理完测试失败之前退出
- 处理失败的 breezejs 保存
- 在处理延迟数组时获取成功的延迟并忽略失败的延迟
- 用于处理成功、失败、重试的异步请求的设计模式?(JavaScript)
- Extjs,在表单中进行标准提交时处理成功或失败
- ASP.NET MVC-在javascript处理程序中导航失败
- 如何处理失败的JQuery DOM转换
- jQuery返回航班5.10在点击处理失败
- 追加和添加类以动画处理失败