scala - Play Framework 2.1 - AngularJS routing - best solution? -
i working way through angularjs tutorial. angular uses it's own js routing mechanism allow single page apps. sample routing file angular looks this:
angular.module('phonecat', []). config(['$routeprovider', function($routeprovider) { $routeprovider. when('/phones', {templateurl: '/partials/phone-list', controller: phonelistctrl}). when('/phones/:phoneid', {templateurl: 'partials/phone-detail', controller: phonedetailctrl}). otherwise({redirectto: '/phones'}); }]);
i trying come place store partials (angular specific html files). ideally ability template them within play (i.e. have them *.scala.html files). can accomplish using a play routes file so:
get /partials/phone_index controllers.application.phone_index
i partials/ controller action this:
def phone_index = action { ok(views.html.partials.phone_index()) }
the solution looking combination of 2 ideals:
- i have sort of mapping lets me visit file under /partial/* , partial file.
- i overriding route specific partial can use controller action dynamically fill data (rare).
any ideas?
when trying similar came conclusion it's better break on 2 parts:
- use play backend interact via ajax calls
- store angular templates in play
public
folder (something/public/angular/
) , use default angularjs way map templates
i know doesn't sound great , doesn't answer question on how it, trying link both frameworks may problematic due way templates , urls mapped in angular, , benefit small change imply lot of work, removing arguably main benefit of both play , angular, rapid development.
this allows separate concerns better, if project grows may important can take angularjs code away standalone app connecting backend, , work fine.
you can see sample code of said (based on todo tutorial of angularjs) in github repository. warn you, code not nice, should give idea , bonus shows how integrate jasmine play, angularjs unit testing.
Comments
Post a Comment