javascript - AngularJS 无法实例化模块

标签 javascript angularjs express angularjs-module

由于某种原因,我的 angularjs 模块无法正确加载。我对此很陌生,并且阅读了很多教程,但我似乎无法使其正常工作。

[17:22:36.338] Error: [$injector:modulerr] Failed to instantiate module wc2013mongoMod due to: [$injector:nomod] Module 'wc2013mongoMod' 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.

我发现了这个问题,它似乎非常接近我的问题的描述:AngularJS: Uncaught Error: [$injector:modulerr] Failed to instantiate module?

它建议重新排列脚本的包含顺序。我尝试将脚本放在正文的末尾,但没有成功。我还尝试将它们放入 <head> 中元素,但仍然没有运气。我在这里做错了什么?

我使用的是 Jade,但生成的 HTML 如下所示:

<!DOCTYPE html>
<html ng-app="wc2013mongoMod">
   <head>
      <title>World Cup 2014 MongoDB Experiment Project</title>
      <link rel="stylesheet" href="/stylesheets/style.css">
      <script src="js/angular/angular.js"></script><script src="js/main.js"></script>
   </head>
   <body>
      <h1>World Cup 2014 MongoDB Experiment Project</h1>
      <p>Welcome to World Cup 2014 MongoDB Experiment Project</p>
      <div ng-controller="teamCtrl">
         <p>Angular JS Controller</p>
      </div>
   </body>
</html>

JavaScript 看起来像这样:

console.log("loaded main.js");

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

myApp.service('teamService', function($http) {
        //delete $http.defaults.headers.common['X-Requested-With'];
        this.getData = function(callbackFunc) {
                $http({
                        method: 'GET',
                        url: '/api'
                        //params: 'limit=10, sort_by=created:desc',
                        //headers: {'Authorization': 'Token token=xxxxYYYYZzzz'}
                }).success(function(data){
                        // With the data succesfully returned, call our callback
                        //callbackFunc(data);
                        console.log("data received");
                        console.log(data);
                }).error(function(){
                        alert("error");
                });
        }
});

myApp.controller('teamCtrl', function($scope, teamService) {
        $scope.data = null;
        console.log("we're in the controller");
        teamService.getData(function(dataResponse) {
                $scope.data = dataResponse;
        });
});

最佳答案

检查差异。 2013 年与 2014 年对比。

<html ng-app="wc2013mongoMod">

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

关于javascript - AngularJS 无法实例化模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23097168/

相关文章:

javascript - 禁止在整个元素 HTML 页面中拖动图像

javascript - 除非存在 : >&lt;/script&gt; after the/head,否则脚本将无法工作

javascript - Cordova 混合应用程序设计 - Controller

javascript - 在 Node.js 中允许 CORS 用于 PUT

node.js - 使用 Express 4 如何重定向到我自己的路线而不丢失请求和响应数据?

javascript - Mongoose Delete 和 Express app.delete 有什么区别

javascript - Vanilla JavaScript For 循环推送名称数组

javascript - 使用 Selenium webdriver 加载动态 url

spring Controller 中的 java.lang.StackOverflowError

javascript - 当前请求不是 [org.springframework.web.multipart.MultipartHttpServletRequest] 类型