简体   繁体   English

我可以在 Angular 中使用(EJS 或 Pug)吗? 或者 Angular 已经带有默认的模板引擎?

[英]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一样ejspughandlebars将帮助您创建动态内容。 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.

相关问题 如何在不执行`res.render`的情况下在nodeJS / express中使用EJS模板引擎? - How can I use the EJS templating engine in nodeJS/express without doing `res.render`? 使用EJS模板引擎时不显示对象值 - Object values are not displayed when I use EJS templating engine 如果我使用Angular作为前端,我是否需要使用ejs或布局? - Will I ever need to use ejs or layouts if I use Angular for frontend? 使用ejs模板引擎时,我是否可以在Node.js的每个页面中包含HTML代码块(如页脚和页眉)? - Can I include HTML blocks of code like footer and header on every page in Node.js whilst using ejs templating engine? 我可以呈现动态内容并使用模板引擎(ejs) - Can i render dynamic content and use a template engine (ejs) Pug (Jade) 模板引擎使我的字符串变形 - Pug (Jade) templating engine is malforming my string ejs模板引擎数据呈现错误 - ejs templating engine data rendering error 使用 EJS 模板引擎在 Node.js 中提交表单后,我不断收到验证器错误 - I keep getting validator errors after submitting my form in Node.js using EJS templating engine 如何使用 EJS 模板引擎将变量传递给内联 javascript? - How do I pass a variable to inline javascript using EJS templating engine? 如何使用 webpack 4 使用 pug 模板引擎成功构建 NodeJS 项目 - How to successfully build NodeJS project with pug templating engine using webpack 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM