2015-08-29 181 views
0

你好,我正在尝试开发一个角度的网络应用程序。我已经将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. 未捕获的错误:[$注射器:NOMOD]模块 'appApp.main' 不可!您拼错了模块名称或忘记加载模块名称。如果注册模块确保您指定依赖关系作为第二个参数。

我该如何解决这个错误?谢谢

+0

您是使用某个构建系统,还是只是在index.html中将脚本文件添加为脚本标记?因为它依赖于文件的顺序,所以应用程序必须是第一个控制器第二个 – tomastrajan

+0

@tomastrajan我使用yeoman fullstack生成器,现在我试图编辑客户端 –

回答

2

的第一件事是:

在你写

ng-app="appApp" 

但在模块定义你写

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

模块名称应该是HTML除非你有另一个appApp模块,并将“appApp.main”模块添加为依赖关系。

另一件事是因为您已经使用“ui-router”,您需要将html中的ui-router的js库文件以及角库文件链接起来。

只需检查js文件的顺序。在第一角度,那么所有库JS,然后应用程序,主,主控制器

+0

我有一个其他模块appApp。对不起,我没有添加它。我将编辑我的问题 –

+0

好吧,然后检查js文件的顺序。首先,角色,然后是所有库js,然后是应用程序,主要,主控制器。 – Indra

+0

谢谢。你能编辑你的答案,并填写上面的评论,所以我可以将其标记为答案? –

1

我认为,

1.You应该调用纳克应用内= “appApp.main” 或

2。您应该首先声明appApp模块。您应该替换main.js中的某些代码

angular.module('appApp.main', []); 

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

另外,请删除main.js中的[ui.router]。它在app.js中声明

+0

a已经有一个appApp模块。我编辑我的问题。对不起,以前没有提供过 –

+0

行。你是否修复了这个问题 –

+0

我发现了这个问题,但我仍然修复了这个问题 –