无法实例化ng app

时间:2016-05-17 10:55:21

标签: javascript angularjs module

我有以下app.js,无法使用模块调用应用程序。附上文件夹结构和代码的截图:

core.module.js:



(function() {
    'use strict';

    angular
        .module('app.core');
})();






(function () {
    'use strict';
   
    angular
        .module('app', [
            'ngRoute',
            'ngCookies',
            'ngAnimate',
            'ngResource',
            'ngCookies',
            'ngTouch',
            'app.core',
            'app.events'
        ])
        .config(config);
        
    config.$inject = ['$routeProvider', '$locationProvider', '$httpProvider'];
    function config($routeProvider, $locationProvider, $httpProvider) {
        $routeProvider
            .when('/', {..}..






Uncaught Error: [$injector:nomod] Module 'app.core' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.



 enter image description here

2 个答案:

答案 0 :(得分:5)

您需要angular.module()上的第二个参数;

请参阅Document

  

//创建一个新模块

     

var myModule = angular.module(' myModule',[]);

angular
    .module('app.core',[]);

答案 1 :(得分:0)

  1. angular.module('app.core', []) is to create a new module without any module dependency.
  2. angular.module('app.core') is to retrieve an existing module whose name is app.core.

So to create angular module, you will have to write angular.module('app.core', []).