AngularJS 仅适用于单页应用程序 (SPA) 吗?

问题描述:

我们正在寻找构建我们正在创建的应用程序前端的选项,并正在尝试评估一种对我们有用的工具,并为我们提供前进的最佳平台.

We are looking at options to build the front end of an application we are creating and are trying to evaluate a tool that will work for us and give us the best platform to move forward.

这是一个 Node.js 项目.我们最初的计划是使用 Express 并沿着这条路线走下去,但我们决定在开始这个阶段之前最好先回顾一下那里有什么.我们的应用程序有几个我们认为不适合单页模型的区域,因为它们从应用程序的角度来看是相关的,但从视图的角度来看却不是.

This is a Node.js project. Our initial plan was to use Express and go down that route, but we decided that before we kick off this stage it might be best to review what is out there. Our application has several areas which we don't believe fit the single-page model in that they are related from an application perspective, but not from a view one.

我们已经看到了一些可以用来构建客户端的框架,例如 Backbone.jsMeteor 等,还有 AngularJS.

We have seen a few of the frameworks we could use to build out the client like Backbone.js, Meteor, etc. and also AngularJS.

这可能是一个相当明显的问题,但我们似乎无法解读 AngularJS 是纯粹用于单页应用程序还是可以用于多页应用程序,例如 Express.

This may be a fairly obvious question, but we cannot seem to decipher if AngularJS is purely for single-page application or it can be used for multi-page applications like Express for instance.

2013 年 7 月 17 日更新只是为了让人们了解情况,我将在整个流程中更新这个问题.我们现在将一起构建所有东西,我们将看到它的表现如何.我们联系了一些比我们更擅长 AngularJS 的人,并提出了关于拆分共享上下文的较大应用程序的问题,但在单个页面上工作可能太大.

UPDATE 17 July 2013 Just to keep people in the loop, I will be updating this question as we go through the process. We are going to build everything together for now, and we will see how well that performs. We have reached out to a few people who are more qualified with AngularJS than us and posed the question regarding splitting up larger applications that share context, but may be too large working on a single page.

共识是,我们可以为多个静态页面提供服务,并创建仅适用于这些页面的 AngularJS 应用程序,有效地创建 SPA 集合并使用标准链接将这些应用程序链接在一起.现在我们的用例非常具体,因为我们的解决方案有多个应用程序,正如我所说,我们将首先尝试单一代码库并从那里进行优化.

The consensus was that we could serve multiple static pages and create AngularJS applications that work with only those pages, effectively creating a collection of SPA and linking those applications together using standard linking. Now our use case is very specific as our solution has several applications, and as I said we are going to try the single code base first and optimise from there.

2016 年 6 月 18 日更新该项目一落千丈,所以我们从来没有时间做太多事情.我们最近再次使用它,但不再使用 angular,而是使用 React.我们仍在使用上一次更新中概述的架构,其中我们使用 express 和自包含应用程序,因此例如,我们在 express 中有一个 /chat 路由来提供我们的 React 聊天应用程序,我们有另一个路由 /projects 提供项目应用程序等等.我们看待它的方式是每个应用程序在其功能集方面都是一个聚合根,它需要能够独立才能被视为一个应用程序本身.从技术上讲,所有信息都在那里,它只是基本的表达方式以及您想要使用的任何客户端应用程序构建优势.

UPDATE 18 June 2016 The project fell of a cliff, so we never got round to getting too much done. We have picked it up again recently, but are no longer using angular and are using React instead. We are still using the architecture outlined in the previous update, where we use express and self contain apps, so for example, we have a /chat route in express that serves up our React chat app, we have another route /projects that serves up the projects app and so on. The way we are kinda looking at it is each app is an aggregate root in terms of its feature set, it needs to be able to standalone for it to be considered an app in itself. Technically, all the information is out there, its just basic express and whatever flavour of client side app building goodness you want to use.

完全没有.您可以使用 Angular 构建各种应用程序.客户端路由只是其中的一小部分.

Not at all. You can use Angular to build a variety of apps. Client-side routing is just a small piece of that.

您有大量功能可以在客户端路由之外使您受益:

You have a large list of features that will benefit you outside of client-side routing:

  • 双向绑定
  • 模板
  • 货币格式
  • 复数
  • 可重复使用的控件
  • RESTful api 处理
  • AJAX 处理
  • 模块化
  • 依赖注入

认为所有这些只能在单页应用程序中使用"的想法很疯狂.当然不是……这就像在说Jquery 只适用于有动画的项目".

It's crazy to think that all of that "could only be used in a single page app". Of course not.. that's like saying "Jquery is only for projects with animations".

如果它适合您的项目,请使用它.

If it fits your project, use it.