[英]Routing express to ng2 without template engine
我已經生成了默認的快速應用程序,我修改了它在app.js
文件中有以下幾行。
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 { }
in和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模板引擎和我的新error.html
和index.html
文件,我總是會看到錯誤頁面,而不是我的ng2托管索引。 有什么想法嗎?
現在最好的選擇是使用ejs(引擎)並將其配置為接受和呈現html。
碼:
app.set('views',path.join( __ dirname ,'views'));
app.set('view engine','ejs'); //模板引擎
注意:您的所有視圖或模板都應該是.html擴展名
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.