【发布时间】:2015-05-28 03:21:17
【问题描述】:
我正在尝试在线获取 express/angular 应用程序,但遇到了一个令人困惑的错误。控制台读数指示如下:
Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:nomod] Module 'app' 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.
我知道这通常是为未正确包含的依赖项保留的,但是当它用于应用程序本身时呢?我有以下“应用程序:”声明
server.js:
var app = express();
//other init code here
module.exports = app;
application.js:
var app = angular.module('app', []);
index.jade
doctype html
html(lang="en" ng-app="app")
head
title Bloom
link(rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css")
//- link(rel="stylesheet" type="text/css" href="/foundation.min.css")
link(rel="stylesheet" type="text/css" href="/main.css")
script(type="text/javascript", src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.js")
script(type="text/javascript", src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js")
script(type="text/javascript", src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js")
script(type="text/javascript", src= "/angular-ui-router.min.js")
script(type="text/javascript", src= "/ui-bootstrap-tpls.min.js")
script(type="text/javascript", src= "/controllers/home.js")
script(type="text/javascript", src= "/routes.js")
script(type="text/javascript", src= "/application.js")
body
div(ui-view)
这里发生了什么?我不知道如何解决这个问题。
【问题讨论】:
-
这是一个角度错误,因此可能与 express 无关,除非 express 无法提供 angular 所需的静态文件。
-
您是否查看了
chrome中的resources选项卡以确保所有依赖项都已有效加载?在您的服务器中,您是否提供了静态文件:var path = require('path');app.use(express.static(path.join(__dirname, 'public'))); -
很抱歉格式不好,但我在加载服务器时也遇到了这些 404 错误。这和它有什么关系吗? localhost/:1 GET localhost:3000/main.css localhost/:1 GET localhost:3000/routes.js localhost/:1 GET localhost:3000/ui-bootstrap-tpls.min.js localhost/:1 GET localhost:3000/controllers/home.js localhost/:1 GET localhost:3000/application.js localhost/:1 GET localhost:3000/angular-ui-router.min.js'
-
他们显示的是 200 还是 304 状态码?
标签: javascript angularjs node.js