Play Framework 2.1 - AngularJS routing - best solution?

前端 未结 7 1783
既然无缘
既然无缘 2020-12-23 16:57

I am working my way through the AngularJS tutorial. Angular uses it\'s own JS routing mechanism to allow for single page apps. A sample routing file for Angular looks like t

相关标签:
7条回答
  • 2020-12-23 17:52

    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.

    0 讨论(0)
提交回复
热议问题