【问题标题】:Dependency injection bug: unable to instantiate 'app'依赖注入错误:无法实例化“应用程序”
【发布时间】: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)

这里发生了什么?我不知道如何解决这个问题。

【问题讨论】:

标签: javascript angularjs node.js


【解决方案1】:

您需要提供静态文件(脚本、css...)

Node Js Express : how to serve static files(css, js...) :

假设您将静态文件放在 public 文件夹中

var app = express();

app.use(express.static(__dirname + '/public'));

【讨论】:

    猜你喜欢
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    • 2014-02-28
    • 2018-05-26
    • 2021-11-14
    • 2017-11-11
    • 1970-01-01
    • 2019-11-23
    相关资源
    最近更新 更多