2015-09-04 71 views
0

未捕获错误:[$ injector:nomod]模块'myApp'不可用!您拼错了模块名称或忘记加载模块名称。如果注册模块确保您指定依赖关系作为第二个参数。 http://errors.angularjs.org/1.2.16/ $喷油器/ NOMOD?P0 = MyApp来我在运行Angular时遇到以下错误

以下是我的代码片断

Uncaught Error: [$injector:nomod] Module 'myApp' 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. 

http://errors.angularjs.org/1.2.16/ $喷油器/ NOMOD?P0 = MyApp来

以下是我的代码片断

(function() { 
    angular.module('myApp').controller('MainCtrl', function($scope) { 
     $scope.data = { 
      Colors: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"] 
     } 
    }); 

    angular.module('myApp').controller('OverviewCtrl', function($scope) { 
     $scope.list1 = { 
      title: 'AngularJS - Drag Me' 
     }; 

     $scope.list2 = {}; 
    }); 

}()); 
+0

你需要使用它之前先创建模块(模块的第二个参数)只有一次。即'angular.module('myApp',[])' – PSL

+0

谢谢你的作品 – django

回答

1

尝试首先定义myApp时,您正在使用getter语法,而不是setter语法。

在尝试将控制器连接到它之前,您需要创建myApp模块。请注意,它有两个参数,一个字符串名称和一个依赖关系数组。

angular.module('myApp', []).controller('MainCtrl', function($scope) { 

一旦你的模块创建,您可以通过吸气语法引用它:

angular.module('myApp').controller('OverviewCtrl', function($scope) { 
+0

谢谢你的作品 – django

+0

@django欢迎你:)。如果它适合你,虽然它被标记为重复,但你也可以接受我的回答,这样碰到的其他人也可以用它作为解决方案。 –

相关问题