2017-12-12 7 views
0

をポリマーにノードから変数を渡す方法、サーバー上のクライアントとのNode.js上のポリマーを使用して:私app.jsに

res.render('ingrid_2.ejs', { 
    num_visitors: 10 
}); 

私のポリマーテンプレートに

properties: { 
     visitors: 
     { 
     type: Object, 
     value: 200 
     } 
    } 

を接続する方法二つ?これに.ejsファイル変数を使用できますか?

ingrid_2.ejsで
+0

私は.ejsファイルの変数を知りませんが、データベースを介して伝えれば、単純すぎるでしょうか?サーバー側とクライアント側の両方が同じデータベースにアクセスできるためです。データ型のために多くの方法があります。 (ユーザーまたは一般データごとの特別なデータ) – HakanC

答えて

0

、カスタム要素のプロパティとしてnum_visitorsを渡すことができます。

<link rel="import" href="/components/my-component/my-component.html"> 
<my-component visitors="<%- num_visitors %>"></my-component> 

ページをロードすると、あなたのEJSテンプレートがレンダリングされると、出力は次のようになります。

コンポーネントオブジェクト内
<link rel="import" href="/components/my-component/my-component.html"> 
<my-component visitors="10"></my-component> 

(私はtype: Numbertype: Objectを変更することはお勧めしますが。)、this.visitorsは、10になります

関連する問題