依赖注入错误:无法实例化'app'

Dependency injection bug: unable to instantiate 'app'

本文关键字:app 实例化 注入 错误 依赖      更新时间:2023-09-26

我正试图在网上获得一个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.

我知道这通常是为未正确包含的依赖保留的,但是当它用于应用程序本身时呢?我对'app '做了如下声明:

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)

这是怎么回事?我不知道如何解决这个问题。

您需要提供您的静态文件(脚本,css…)

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

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

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