[英]Can I use (EJS or Pug) with Angular? or Angular already comes with a default templating engine?
Does Angular already come with a templating engine? Angular 是否已经带有模板引擎?
If I wish to work with MEAN stack then is it valid to use EJS or Pug as a templating engine?如果我希望使用 MEAN 堆栈,那么使用 EJS 或 Pug 作为模板引擎是否有效? If yes then how can I implement it?
如果是,那么我该如何实施?
In Angular you can use Interpolation
which refers to embedded expression in the markup text.在 Angular 中,您可以使用
Interpolation
,它指的是标记文本中的嵌入表达式。 To use interpolation
you need to use double-curly braces like {{}}
for example:要使用
interpolation
您需要使用像{{}}
这样的双花括号,例如:
<h1>CustomerName: {{ name }} </h1>
you can also use Template Expression
which produce a value and also appears in double-curly-braces.您还可以使用
Template Expression
,它产生一个值,也出现在双花括号中。
But besides this you can use Nodejs, Expressjs's template-engine
like ejs
, pug
and handlebars
will help you to create dynamic content.但是,除了这个,你可以使用的NodeJS,Expressjs的
template-engine
一样ejs
, pug
和handlebars
将帮助您创建动态内容。 You can choose any one of them.您可以选择其中任何一种。 For example, in order to use
ejs
you need to install it first.例如,为了使用
ejs
您需要先安装它。 You can write below command in your terminal您可以在终端中编写以下命令
npm i ejs
and import it in your root file并将其导入到您的根文件中
const ejs = require ('ejs');
and then you need to setup view engine like然后你需要像这样设置视图引擎
app.set('view engine', 'ejs');
Then you need to save all your views
file in .ejs
extension然后您需要将所有
views
文件保存在.ejs
扩展名中
const express = require('express');
const ejs = require('ejs');
const app = express();
app.set('view engine', 'ejs');
app.get('/', (req, res) => {
res.render('index', { name: 'Hello' });
});
app.listen(3000, () => console.log('Server is running'));
Now You can access value of the name in your ejs
file dynamically like现在您可以像这样动态访问
ejs
文件中名称的值
<%=name %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.