简体   繁体   English

Angular2 + Scala Play2?

[英]Angular2 + Scala Play2?

I am somewhat new to the domain of web development. 我对Web开发领域有些新意。 I am investigating Play2 and am trying to understand, do you need some kind of JS frontend framework to go with Play2 and Scala? 我正在调查Play2,我正在努力理解,你需要某种JS前端框架来配合Play2和Scala吗?

I notice that Play2 has a template engine, but it seems that it generates the HTML on the server and sends it to the browser. 我注意到Play2有一个模板引擎,但似乎它在服务器上生成HTML并将其发送到浏览器。 Does this mean that the need for a JS frontend like Angular2 is made irrelevant? 这是否意味着需要像Angular2这样的JS前端无关紧要? Or is there still a reason to use Angular2 in a Play2 application? 或者仍然有理由在Play2应用程序中使用Angular2? What instances would it make sense and why? 它有什么意义,为什么?

I have some experience of using Play 2 with AngularJS (currently rewriting frontend to Angular2). 我有使用Playular 2和AngularJS的经验(目前正在重写Angular2的前端)。
I use Play 2 (scala) only for RESTful JSON backend, which is just great for this purpose and I use Angular for single page application frontend. 我只将Play 2(scala)用于RESTful JSON后端,这对于此目的非常有用,我将Angular用于单页面应用程序前端。 I find this combination brilliant. 我发现这个组合很棒。

My project is hosted on GitHub, you can check it out here 我的项目是在GitHub上托管的,你可以在这里查看

There are three directories in the root: 根目录中有三个目录:

  • restful with all backend stuff, written in scala, using Slick for DB, taking advantage of Play evolutions and all other stuff. 宁静与所有后台的东西,用Scala编写,用油滑的DB,以游戏的演变和所有其他的东西的优势。
  • angularjs-client-deprecated with AngularJS code. 使用 AngularJS代码弃用angularjs-client I used angular-resource for making calls to backend. 我使用angular-resource来调用后端。
  • client with Angular2 code. 客户端使用Angular2代码。 There is nothing there so far except for my experiments, however I've written a simple service for authentication with security token. 到目前为止除了我的实验之外什么都没有,但是我已经用安全令牌编写了一个简单的服务进行身份验证。

To summarise, I've been developing my project for almost 2 months so far, mainly to learn both Scala and AngularJS (now Angular2). 总而言之,到目前为止,我已经开发了近2个月的项目,主要是为了学习Scala和AngularJS(现在是Angular2)。

If you're planning to use JS framework for frontend, I would recommend you to use Play2 only for RESTFul Json backend. 如果您计划使用JS框架作为前端,我建议您将Play2用于RESTFul Json后端。 I don't see a reason to use Play2 html template engine in this case. 在这种情况下,我没有看到使用Play2 html模板引擎的原因。

Play is more about Server Side templating, which isn't all that useful if you're using Angular. Play更多的是关于服务器端模板,如果您使用的是Angular,那么这并不是很有用。 It can be done, but it comes with some overhead. 它可以完成,但它带来了一些开销。 I've worked with Scalatra in the past and it worked really well for me. 我过去曾与Scalatra合作过,对我来说效果非常好。 http://scalatra.org/ http://scalatra.org/

Other options include Spray, which is very similar from the outside, but uses Akka internally and uses non-blocking I/O, similar to Play! 其他选项包括Spray,它与外部非常相似,但在内部使用Akka并使用非阻塞I / O,类似于Play!
http://spray.io/ http://spray.io/

With angular it is better to go with simple rest/http api like Akka-IO or spray for data and other stuff. 对于角度,最好使用简单的rest / http api(如Akka-IO)或喷洒数据和其他东西。 Play will be less relevant with Angular. 与Angular相比,Play的相关性较低。

As others have pointed out Play2 isn't really the best option for building responsive websites. 正如其他人所指出的,Play2并不是构建响应式网站的最佳选择。 I have a seed project which can help you get started with Akka Http and Angular 5...already configured to deploy to Heroku in a single web dyno. 我有一个种子项目可以帮助你开始使用Akka Http和Angular 5 ......已经配置为在单个web dyno中部署到Heroku。

https://github.com/jdschmitt/akka-angular-heroku https://github.com/jdschmitt/akka-angular-heroku

Check it out. 看看这个。 I hope it helps anyone landing here looking for a way to manage back-end and front-end in a single repo for simple projects. 我希望它可以帮助任何人登陆这里寻找一种方法来管理简单项目的单个仓库中的后端和前端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM