Angular2 + Scala Play2?
Asked Answered
S

4

9

I am somewhat new to the domain of web development. I am investigating Play2 and am trying to understand, do you need some kind of JS frontend framework to go with Play2 and 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. Does this mean that the need for a JS frontend like Angular2 is made irrelevant? Or is there still a reason to use Angular2 in a Play2 application? What instances would it make sense and why?

Synonym answered 13/2, 2016 at 9:24 Comment(1)
see github.com/sbahmani/Play-Angul2Chud
T
4

I have some experience of using Play 2 with AngularJS (currently rewriting frontend to 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. I find this combination brilliant.

My project is hosted on GitHub, you can check it out here

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.
  • angularjs-client-deprecated with AngularJS code. I used angular-resource for making calls to backend.
  • client with Angular2 code. 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).

If you're planning to use JS framework for frontend, I would recommend you to use Play2 only for RESTFul Json backend. I don't see a reason to use Play2 html template engine in this case.

Trypsin answered 24/4, 2016 at 16:0 Comment(0)
K
3

Play is more about Server Side templating, which isn't all that useful if you're using 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. 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!
http://spray.io/

Kaffiyeh answered 13/2, 2016 at 11:4 Comment(0)
A
1

With angular it is better to go with simple rest/http api like Akka-IO or spray for data and other stuff. Play will be less relevant with Angular.

Amblyopia answered 13/2, 2016 at 9:51 Comment(2)
I was wanting to do a responsive web site. As I understood Play2 was the thing to use for?Synonym
Responsive is really not something Play2 specializes in, if you want Responsive, you should look at Bootstrap or Angular-Material.Kaffiyeh
J
1

As others have pointed out Play2 isn't really the best option for building responsive websites. 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.

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.

Jaynes answered 18/2, 2018 at 21:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.