“由于”在角度和平均堆栈中“无法实例化模块'app'

时间:2014-11-22 19:08:39

标签: javascript angularjs node.js express pug

所以我最近玩了表达节点玉和角度的平均堆栈;实际上我觉得玉器有问题;我为复杂性道歉,但我真的无法弄清楚,希望从外面看到一些不同的观点;所以情况就是这样:

消息本身:

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.

http://errors.angularjs.org/1.3.3/$injector/nomod?p0=app
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:63:12

好的,我们去63角js:return new ErrorConstructor(message); - >好吧,它没有说什么,但有些人认为这个问题确实隐藏在任何地方;

    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:1747:17

转到1747:throw $injectorMinErr('nomod', "Module '{0}' is not available! You either misspelled " + - >再一次没有什么可理解的;你觉得怎么样?

    at ensure (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:1671:38)
    at module (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:1745:14)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:4041:22
    at forEach (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:322:20)
    at loadModules (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:4025:5)
    at createInjector (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:3951:11)
    at doBootstrap (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:1434:20)
    at bootstrap (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js:1455:12)
http://errors.angularjs.org/1.3.3/$injector/modulerr?p0=app&p1=Error%3A%20%….googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.3%2Fangular.js%3A1455%3A12) 

文件结构:

_client
   vendor //for bower installations
   styles 
   application
      angularCore.js

_server
   views
      core.jade
      states
         home.html

server.js

>

server.js :


==stuff===

app.set('views', path.join(__dirname, '_server/views'));
app.set('view engine', 'jade');

app.use(express.static(path.join(__dirname, '_client/')));

app.get('/states/:Path', function(req, res) {
   res.render('states/' + res.params.Path + '.html');
 });

 app.get('*', function(req, res) {
   res.render('core');
   console.log(res);
 });

==stuff==

_server / views / core.jade:

doctype html
html(lang="en")
  head
    link(rel="shortcut icon", href="favicon.ico", type="image/x-icon")
    link(rel="stylesheet", href="styles/bootstrap.css")
    link(rel="stylesheet", href="vendor/toastr/toastr.min.css")
    link(rel="stylesheet", href="styles/core.css")

  body(ng-app='app')
    div(ng-view)
     h1 Some text

    script(type='text/javascript', src='vendor/jquery/dist/jquery.min.js')
    script(type='text/javascript', src='https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js')
    script(type='text/javascript', src='http://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular-route.js')
    script(type='text/javascript', src='http://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular-resource.js')
    script(type='text/javascript', src='./application/angularCore.js')

_client / application / angularCore.js:

var app = angular.module('app', ['ngResource', 'ngRoute']);

app.config(function($locationProvider, $routeProvider) {
  $locationProvider.html5mode(true);
  $routeProvider
    .when('/', {
      templateUrl: '/states/home',

所以,如我所见,问题陈述/ home.html没有加载到网络标签中;

      controller: 'controllerMain'
    });
  }


app.controller('controllerMain', function($scope) {
  $scope.myVar = "Hello peolm";
});

_server / views / states / home.html:

<h1>That's the state home</h1>
<h2>{{myVar}}</h2>

所以应用程序的逻辑是去localhost:3030到'/',然后由于angular的

when('/', {
      templateUrl: '/states/home',

并表达

app.get('/states/:Path', function(req, res) {
   res.render('states/' + res.params.Path);
 });

收到home.html,我们很好,但home.html没有呈现,甚至没有加载,我不知道因为什么; 浏览器,客户端下载的所有文件,“home.html”除外;

这就是主要问题:所有内容都已下载,我为什么不能找到'app'模块?

2 个答案:

答案 0 :(得分:2)

这很有趣。

问题在于:$locationProvider.html5mode(true);好吧,没有html5mode,但是html5 M ode;

答案 1 :(得分:1)

乍一看,我觉得你在这里缺少.html

app.get('/states/:Path', function(req, res) { 
   res.render('states/' + res.params.Path + '.html');
});