简体   繁体   English

MEAN堆栈:未定义角度

[英]MEAN stack: angular is not defined

I have been searching for answer to my problem for two full days now without results. 我一直在寻找整整两天没有结果的问题的答案。 I know there are a lot of threads about "angular is not defined", but their answers have been of no avail. 我知道有很多关于“未定义角度”的主题,但是他们的答案毫无用处。 The starting point is that I have deployed MEAN stack for a SPA on DigitalOcean. 起点是我在DigitalOcean上为SPA部署了MEAN堆栈。 There is also grunt in use. 还在使用咕use声。 The app has been running successfully right until grunt tries to run the server.js file which has angular.module(... call. 该应用程序已成功运行,直到grunt尝试运行具有angular.module(...调用)的server.js文件。

The folder structure is following: 文件夹结构如下:

node_modules node_modules

  • bunch of modules like there should be 一堆模块应该有

public 上市

  • lib LIB
  • angular, angular-resource, jquery etc folders 角,角资源,jQuery等文件夹

routes 路线

  • index.js index.js

src SRC

views 意见

  • index.html, index.jade, layout.jade index.html,index.jade,layout.jade

bower.json bower.json

gruntfile.js gruntfile.js

karma.conf.js karma.conf.js

package.json 的package.json

server.js server.js


bower.json bower.json

{
  "name": "meanjs",
  "version": "0.3.2",
  "description": "Fullstack JavaScript with MongoDB, Express, AngularJS, and Node.js.",
  "dependencies": {
    "bootstrap": "~3",
    "angular": "~1.3.0",
    "angular-resource": "1.3.0",
    "angular-animate": "~1.3.0",
    "angular-mocks": "~1.3.0",
    "angular-bootstrap": "~0.11.0",
    "angular-ui-utils": "~0.1.1",
    "angular-ui-router": "~0.2.10"
  }
}

server.js server.js

'use strict';
var cheerio = require('cheerio'),
http = require('http'),
iconv = require('iconv-lite'),
request = require('request'),
mongoose = require('mongoose'),
iconv = require('iconv-lite');

angular.module('myapp', []);
var express = require('express');
var app = express();

app.use(express.static(__dirname + '/public'));
app.set('view engine', 'jade');
app.get('/', function (req, res) {
        res.sendfile('./views/index.html');

});
app.listen(80);

index.html 的index.html

<!DOCTYPE html>
<html lang="en" ng-app="myapp">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script>
<script src="/opt/mean/server.js"></script>
         <meta charset="UTF-8">
         <title>Myapptitle</title>
</head>
<body>
        <div id="app">
            <p>Hallelujah, server is running!</p>
        </div>
</body>
</html>

I have been moving all parts related to the .js files around the index.html file and so on. 我一直在将与.js文件相关的所有部分移到index.html文件周围,依此类推。 The main point of the app is just to have the server.js running and having several different .js file based angular modules that handle JSON files for server.js. 该应用程序的主要目的是让server.js运行,并具有几个基于.js文件的不同角度模块,这些模块可处理server.js的JSON文件。 I just don't have any clues left what to try, please give me some advice. 我只是没有任何线索可以尝试,请给我一些建议。 I will gladly supply you with more code files if necessary. 如有必要,我将很乐意为您提供更多代码文件。

server.js is a Node/Express application and should not contain Angular code. server.js是一个Node / Express应用程序,不应包含Angular代码。 Generally, you'll have a public/ folder for Angular applications and angular.module would generally be called first in public/app.js 通常,您将有一个用于Angular应用程序的public /文件夹,通常在public / app.js中首先调用angular.module

For a really good example of the setup, see http://meanjs.org - Use MEAN.JS to scaffold an example structure real quick and look at both /server.js and public/app.js for usage examples. 有关该设置的一个很好的示例,请参见http ://meanjs.org-使用MEAN.JS快速构建示例结构,并查看/server.js和public / app.js的用法示例。

Lastly, in your HTML file, you would not include the server.js file but instead would include your app.js. 最后,在HTML文件中,将不包括server.js文件,而将包括app.js。 Try to remember that server.js is for server-side Node/Express and is independent of your front-side code. 尝试记住,server.js用于服务器端Node / Express,并且独立于您的前端代码。

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

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