简体   繁体   English

“由于角和均值堆栈而导致实例化模块'app'失败”

[英]“Failed to instantiate module 'app' due to” in angular and mean stack

So I recently played around mean stack with express node jade and angular; 所以我最近在玩特快节点玉和角的均值堆; and actually I think there is a problem in jade somehow; 实际上,我认为翡翠存在某种问题; and I apologise for complexity, but I really can not figure it out, hoping for some different view from the outside; 对于复杂性,我深表歉意,但我实在想不通,希望从外界获得一些不同的看法。 so here is the case: 所以是这样:

the message itself: 消息本身:

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

ok, We go to 63 of angular js: return new ErrorConstructor(message); 好的,我们转到角度js的63: return new ErrorConstructor(message); -> well, it tells nothing, but some idea that the problem is really hiding in nowhere; ->好吧,它什么也没说,但是有些想法表明问题确实隐藏在任何地方;

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

go to this 1747 either: throw $injectorMinErr('nomod', "Module '{0}' is not available! You either misspelled " + -> again nothing to understand here; so what do you think of it? 请转到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) 

File structure: 文件结构:

_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 : _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 : _client / application / angularCore.js:

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

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

so, coz of a problem states/home.html not loaded in network tab as i see; 因此,问题的状态状态/home.html未加载到网络标签中,如我所见;

      controller: 'controllerMain'
    });
  }


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

_server/views/states/home.html: _ SERVER /视图/美国/ home.html的:

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

So the logic of app is go to localhost:3030 to '/', then due to angular's 因此应用的逻辑是将localhost:3030转到'/',然后由于angular的原因

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

and express's 和快递的

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

receive home.html and we're good, but home.html not rendered, not even loaded, and I don't know because of what; 收到home.html,我们很好,但是home.html没有呈现,甚至没有加载,我也不知道是因为什么; All of the files downloaded by browser, by client, except 'home.html'; 浏览器,客户端下载的所有文件,“ home.html”除外;

So that's the main question: all are downloaded, my why cant it find 'app' module? 所以这是主要问题:所有内容都已下载,我为什么找不到“ app”模块?

It's hilarious. 这很滑稽。

The problem was here: $locationProvider.html5mode(true); 问题出在这里: $locationProvider.html5mode(true); well, there is no html5mode, but html5 M ode; 好吧,没有html5mode,但是html5 M ode;

On first glance I think your are missing .html here 乍一看,我认为您在这里缺少.html

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM