1
我已经生成了默认的快速应用程序,我修改了其中的app.js
文件中的以下行。在没有模板引擎的情况下将路由表达为ng2
app.set('views', path.join(__dirname, '/views'));
app.engine('html', require('jade').renderFile);
app.set('view engine', 'html');
在./views目录,我本来layout.jade
,index.jade
和error.jade
。好,那么好。当项目运行时,我会看到索引或错误布局。
现在...我想添加一个最小的angular2安装,以便让ng2管理一个1页的应用程序,其中index.jade
目前是。
所以我把一个app.component.ts
:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent { }
在
和main.ts
文件:
import { bootstrap } from '@angular/platform-browser-dynamic';
import { AppComponent } from './app.component';
bootstrap(AppComponent);
然后,我改变index.jade
到index.html
并补充说:
<html>
<head>
<title>Angular 2 QuickStart</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../public/stylesheets/style.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>
然而, HTML模板引擎和m y新error.html
和index.html
文件,我总是会显示错误页面,而不是我的ng2管理索引。任何想法为什么?
您是否知道这一点?下面的建议说ejs,但我也不想使用模板引擎。使用angular 2选择器来提供index.html文件的正确方法是什么?这样我就可以将前端传递给角度2而不会出现任何奇怪的错误。就像我刷新页面时一样 – wuno