Angular 2 合并 MEAN 堆栈问题
Angular 2 incorporating MEAN stack issue
我正在尝试将后端附加到我的 angular 2 应用程序。我有一个 Server.js 文件抓取了我的 index.html 但我在 index.html
中的 System.import('app').catch(function(err){ console.error(err) });
处出错
错误
SCRIPt5009: 'System' is undefined
index.html
<html>
<head>
<base href="/">
<title>LGR</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
<link rel="stylesheet" href="./app/css/lgr.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err) }); <----ERROR HERE!
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
server.js
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var app = express();
var path = require('path');
mongoose.connect('mongodb://localhost:27017/LGR_db');
app.use('app', express.static(__dirname + "/app"));
app.use('node_modules', express.static(__dirname + "/node_modules"));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, '../LGR', 'index.html'));
});
app.listen('3000', function () {
console.log("Server is running on localhost:3000");
});
我在这里很迷路,任何帮助都会很棒。我想我不明白如何 "define" 系统??
编辑:添加文件夹结构
网络输出
我会说这是因为您要专门发送 index.html
文件,并对 /app
中的内容进行静态服务。如果 systemjs.config.js
文件位于 /app
文件夹中并在 index.html
中引用为 src='/app/systemjs.config.js'
它可能会起作用。
-- 编辑:仍然不能 100% 确定问题出在哪里。我做了我们在其中讨论的所有事情,没有别的。很高兴它能正常工作!
我正在尝试将后端附加到我的 angular 2 应用程序。我有一个 Server.js 文件抓取了我的 index.html 但我在 index.html
中的System.import('app').catch(function(err){ console.error(err) });
处出错
错误
SCRIPt5009: 'System' is undefined
index.html
<html>
<head>
<base href="/">
<title>LGR</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
<link rel="stylesheet" href="./app/css/lgr.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err) }); <----ERROR HERE!
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
server.js
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var app = express();
var path = require('path');
mongoose.connect('mongodb://localhost:27017/LGR_db');
app.use('app', express.static(__dirname + "/app"));
app.use('node_modules', express.static(__dirname + "/node_modules"));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, '../LGR', 'index.html'));
});
app.listen('3000', function () {
console.log("Server is running on localhost:3000");
});
我在这里很迷路,任何帮助都会很棒。我想我不明白如何 "define" 系统??
编辑:添加文件夹结构
网络输出
我会说这是因为您要专门发送 index.html
文件,并对 /app
中的内容进行静态服务。如果 systemjs.config.js
文件位于 /app
文件夹中并在 index.html
中引用为 src='/app/systemjs.config.js'
它可能会起作用。
-- 编辑:仍然不能 100% 确定问题出在哪里。我做了我们在其中讨论的所有事情,没有别的。很高兴它能正常工作!