2016-08-07 6 views
1

デフォルトのエクスプレスアプリケーションを生成しました。このアプリケーションでは、次の行をapp.jsファイルに変更しました。 ./viewsディレクトリ内テンプレートエンジンなしでng2にルーティングする

app.set('views', path.join(__dirname, '/views')); 
app.engine('html', require('jade').renderFile); 
app.set('view engine', 'html'); 

、私はもともとlayout.jadeindex.jadeerror.jadeを持っていました。 OK、これまでのところ良い。プロジェクトが実行されると、インデックスまたはエラーレイアウトが表示されます。

今、最小のangular2インストールを追加したいと考えています.ng2に1ページアプリケーションを管理させるために、index.jadeが現在あります。

だから私はapp.component.ts入れている:その後、私はindex.htmlindex.jadeを変更して、コメントを追加し

import { bootstrap } from '@angular/platform-browser-dynamic'; 
import { AppComponent } from './app.component'; 
bootstrap(AppComponent); 

<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> 

しかし、で

import { Component } from '@angular/core'; 

@Component({ 
    selector: 'my-app', 
    template: '<h1>My First Angular 2 App</h1>' 
}) 

export class AppComponent { } 

中とmain.tsファイルをhtmlテンプレートエンジンとm y new error.htmlindex.htmlファイルの場合、常にng2管理インデックスではなくエラーページが表示されます。なぜどんなアイデア?

+0

これを把握しましたか?以下の提案ではejsと書かれていますが、私もテンプレートエンジンを使いたくありません。角度2セレクタを持つindex.htmlファイルを提供する正しい方法は何ですか。私は奇妙なエラーを出すことなく、フロントエンドを角度2に渡すことができます。ページをリフレッシュするときなど – wuno

答えて

0

ejs(エンジン)を使用し、htmlを受け入れてレンダリングするように設定するのが最善のオプションです。

コード:

app.set( 'ビュー'、path.join(__dirname、 'ビュー'));
app.set( 'ビューエンジン'、 'ejs'); //テンプレートエンジン

app.engine( 'html'、require( 'ejs')。renderFile); //エンジンを使用してHTMLを使用する

注:ビューまたはテンプレートはすべて、.htmlの拡張子でなければなりません。

関連する問題