模块不可用、拼写错误或忘记加载(但我没有)

Module is not available, misspelled or forgot to load (but I didn't)

我对 angular 相当陌生,并且将它与 JSON api 文件一起使用。为了测试,我正在尝试使用免费的 github api(我的函数名称是不同的 json api,我稍后将使用它)。我只是想看看我的功能是否适用于 console.log(),但我在控制台中收到此错误。

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

我拼写MesaViewer完全相同,并且在第二行中看到依赖关系!

var app = angular.module("MesaViewer");
var MainController = function($scope, $location, $http, $routeParams) {

我做错了什么? 以下是我的观点:http://plnkr.co/edit/sZPaFbzbOB6AmVCLL1vq

应该是

var app = angular.module("MesaViewer", []);

这是定义模块所需的语法,您需要数组来显示它没有依赖关系。

您使用

angular.module("MesaViewer");

引用已定义模块时的语法。

你没有正确地声明你的主模块,它在创建模块时需要第二个依赖数组参数,否则它是对现有模块的引用

变化:

var app = angular.module("MesaViewer");

收件人:

var app = angular.module("MesaViewer",[]);

Working Version

当我因为不同的原因得到同样的错误时,我发现了这个问题。

我的问题是我的 Gulp 没有意识到我已经声明了一个新模块,我需要手动 re-run Gulp.

我有同样的问题,但我解决了在 angular.min.js 之前添加 jquery.min.js。

我有同样的错误,但我解决了它,这是 AngularJS 提供程序中的语法错误

我有同样的错误并修复了它。 结果证明这是一个愚蠢的理由。

This was the culprit: <script src="app.js"/>

Fix: <script src="app.js"></script>

确保您的脚本标签正确结束!

使用 AngularJS 1.6.9+

还有一件事,当你声明变量名与模块名不同时也会发生。

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

要消除此错误,

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

更改模块名称类似于 var 声明的名称,反之亦然 -

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

确保先将模块和控制器插入 index.html。 然后在您的模块中使用此代码 var app = angular.module("MesaViewer", []);

当我的服务声明在非调用函数 (IIFE) 中时,我遇到了这个错误。下面的最后一行没有 运行 的额外 () 并定义服务。

(function() {
    "use strict";

    angular.module("reviewService", [])
        .service("reviewService", reviewService);

    function reviewService($http, $q, $log) {
        //
    }
}());