2017-06-07 44 views
1

我正在尝试创建这个非常简单的meanstack应用程序,它几乎在运行,但有一个未捕获的引用错误,当它重定向到索引页时。服务器运行正常。浏览器正如索引页面中显示文本(正在加载..)。但是,自定义标签应该与选择器一起去app.component.ts并打印出“我的第一个应用程序”,但它没有。相反,它在控制台中表示“应用程序未定义”。Angular:Uncaught ReferenceError:应用程序未定义

任何人都可以帮忙吗?我是新来的平角,如此亲切详细。如果有任何(或许多)错误,请原谅我的愚蠢错误。

这是我的index.html

<html> 
<head> 
<title>MyTaskList</title> 
<meta charset="UTF-8"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" href="styles.css"> 
<!-- 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);});</script> 
</head> 
<!-- 3. Display the application --> 
<body> 
<my-app>Loading...</my-app> 
</body> 
</html> 

这是我app.component.ts

import { Component } from '@angular/core'; 
@Component({ 
selector: 'my-app', 
template: 'My First Angular App' 
}) 
export class AppComponent { } 

我index.js

var express = require('express'); 
var router = express.Router(); 

router.get('/', function(req, res, next){ 
res.render('index.html'); 
}); 

module.exports = router; 

最后我server.js(起点)

var express = require('express'); 
var path = require('path'); 
var bodyParser = require('body-parser'); 

var index = require('./routes/index'); 
var tasks = require('./routes/tasks'); 

var port = 3000; 

var app = express(); 

app.set('views', path.join(__dirname, 'views')); 
app.set('view engine','ejs'); 
app.engine('html', require('ejs').renderFile); 
app.use(express.static(path.join(__dirname, 'client'))); 
app.use(bodyParser.json()); 
app.use(bodyParser.urlencoded({extended: false})); 

app.use('/', index); 
app.use('/api', tasks); 

app.listen(port, function(){ 
console.log('Server started on port '+port); 
}); 
+0

可以将应用放在引号中..?也许你的应用程序文件不在根目录 – Wernerson

+0

@Wernerson:非常感谢。它的工作(把应用程序引号)。从来没有想过,这可能是原因。 –

+0

我会很高兴,如果你可以upvote我的答案,并将其标记为接受:) – Wernerson

回答

2

app放在引号中,因为Javascript认为应用程序是一个变量,但它实际上应该是一个字符串。

相关问题