Play Framework 2.1 – AngularJS routing – best solution?

When I was trying something similar I came to the conclusion that it’s better to break it on 2 parts:

  • Use Play as a backend you interact with via Ajax calls
  • Store the Angular templates in Play public folder (something like /public/angular/) and use the default AngularJs way to map the templates

I know it doesn’t sound great and really doesn’t answer your question on how to do it, but trying to link both frameworks may be problematic due to the way templates and their urls are mapped in Angular, and the benefit will be very small as any change will imply a lot of work, thus removing the arguably main benefit of both Play and Angular, rapid development.

This also allows you to separate concerns better, which if your project grows may be important as you can just take the AngularJS code away as a standalone app connecting to a backend, and it will work fine.

You can see some sample code of what I said (based on the TODO tutorial of AngularJS) in this Github repository. I warn you, the code is not too nice, but should give you an idea and as a bonus shows you how to integrate Jasmine into Play, for AngularJS unit testing.

Leave a Comment