node.js Jade模板和angularjs的实际使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20989024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:36:44  来源:igfitidea点击:

Actual use of Jade template and angularjs

node.jsangularjsexpresspug

提问by Haresh

I am building a website using nodejs and express. How to make divisions in a page dynamic? Is Jade used for that? if not how to do it?what is angularjs used for? Please help i searched a lot on google and i couldn't get a clarity in the usage of them.

我正在使用 nodejs 和 express 构建一个网站。如何使页面中的分区动态化?玉是用来做这个的吗?如果不是怎么办?angularjs 是做什么用的?请帮助我在谷歌上搜索了很多,但我无法清楚地了解它们的用法。

回答by null

Jade creates the html used in the browser on the server-side. The browser executes a request to the web-server, the web-server executes Jade, which will generate the html that will be sent to the browser. This server-side content generationhas been very common in the last ~20 years, but it has quite some cons when building rich internet application. Mostly this has to do with performance and client state tracking.

Jade 在服务器端创建浏览器中使用的 html 。浏览器向网络服务器执行请求,网络服务器执行 Jade,它将生成将发送到浏览器的 html。在过去的大约 20 年中,这种服务器端内容生成非常普遍,但是在构建富 Internet 应用程序时它有很多缺点。这主要与性能和客户端状态跟踪有关。

AngularJS is a client-side MVC/MVVMlike framework to build so called Single Page Applications(SPA), which allows you to have the complete user interface flow, all content generation and state tracking to be done at the client side. It even allows you to build offline applications. From the developer point of view this feels much more like building a desktop application where the client knowsthe state of the user interface. From the user point of the view the website will respond much smoother and snappier because the UI is all generated locally.

AngularJS 是一个类似于MVC/MVVM的客户端框架,用于构建所谓的单页应用程序(SPA),它允许您拥有完整的用户界面流、所有内容生成和状态跟踪在客户端完成。它甚至允许您构建离线应用程序。从开发人员的角度来看,这感觉更像是构建一个客户端知道用户界面状态的桌面应用程序。从用户的角度来看,由于 UI 都是在本地生成的,因此网站的响应会更加流畅和快速。

Note: SPA does notmean that you can only have one page in your website. It's a technical term where the browser downloads one page (~/index.html), which contains the complete or partial web application. The user technically never leaves this page, but the content (pages) is dynamically swapped in and out from this placeholder page.

注:SPA并不能意味着你只能有一个页面在您的网站。这是一个技术术语,浏览器下载一个页面 (~/index.html),其中包含完整或部分的 Web 应用程序。从技术上讲,用户永远不会离开这个页面,但内容(页面)会动态地从这个占位符页面换入和换出。

To most common way to provide data to a SPAis via RESTfulweb services. AngularJS comes with builtin supportfor REST.

SPA提供数据的最常见方式是通过RESTfulWeb 服务。AngularJS内置了对 REST 的支持

Some developers combine server-side content generation techniques with AngularJS, but there's actually no real need for this.

一些开发人员将服务器端内容生成技术与 AngularJS 相结合,但实际上并没有真正的需要。

回答by alex

Jade is used as a template engine on both server-side and client-side. Yes, it can update a page dynamically, you just have to compile your jade templates to a javascript functions (using jade -cor something similar).

Jade 用作服务器端和客户端的模板引擎。是的,它可以动态更新页面,您只需要将 jade 模板编译为 javascript 函数(使用jade -c或类似的东西)。

Yes, you can use angular.js with it, but I see no real need to use two template engines in your project. Suggesting to just stick with jade, unless you know what are you doing.

是的,您可以将 angular.js 与它一起使用,但我认为没有必要在您的项目中使用两个模板引擎。建议只用玉,除非你知道自己在做什么。