Ian*_*ary 54 javascript json module angularjs angularjs-injector
我对角度相当新,并将其与JSON api文件一起使用.为了测试,我正在尝试使用免费的github api(我的函数名称是针对不同的json api,我将在稍后使用).我只是想看看我的功能是否正常console.log(),但我在控制台中收到此错误.
未捕获错误:[$ injector:modulerr]由于以下原因无法实例化模块MesaViewer:错误:[$ injector:nomod]模块'MesaViewer'不可用!您要么错误拼写了模块名称,要么忘记加载它.如果注册模块,请确保将依赖项指定为第二个参数.
我MesaViewer在两者中拼写完全相同,并且在第二行中看到了依赖关系!
var app = angular.module("MesaViewer");
var MainController = function($scope, $location, $http, $routeParams) {
Run Code Online (Sandbox Code Playgroud)
我做错了什么?这是我的插件:http: //plnkr.co/edit/sZPaFbzbOB6AmVCLL1vq
Mat*_*itt 88
它应该是
var app = angular.module("MesaViewer", []);
Run Code Online (Sandbox Code Playgroud)
这是定义模块所需的语法,您需要数组来显示它没有依赖项.
你用的是
angular.module("MesaViewer");
Run Code Online (Sandbox Code Playgroud)
引用已定义的模块时的语法.
cha*_*tfl 14
您未正确声明主模块,在创建模块时需要第二个依赖项数组参数,否则它是对现有模块的引用
更改:
var app = angular.module("MesaViewer");
Run Code Online (Sandbox Code Playgroud)
至:
var app = angular.module("MesaViewer",[]);
Run Code Online (Sandbox Code Playgroud)
我有同样的错误并修复它.事实证明这是一个愚蠢的原因.
这是罪魁祸首:
<script src="app.js"/>固定:
<script src="app.js"></script>
确保您的脚本标记正确结束!
当我的服务声明位于非调用函数 (IIFE) 内时,我收到此错误。下面的最后一行没有额外的 () 来运行和定义服务。
(function() {
"use strict";
angular.module("reviewService", [])
.service("reviewService", reviewService);
function reviewService($http, $q, $log) {
//
}
}());
Run Code Online (Sandbox Code Playgroud)