I have tried to write simple crud application using scala play framework and angular. And I saw that there are two options:
1) I can use play framework route (in file conf/routes)
2) I can use angular routes.
And what should i do?
I think I should use angular, when page doesn't use scala and database, and scala route when it does.
But this will divide and mix urls and I don't think it is the best idea.
Is there any better solution to this?
1 Answers
You actually have few possible options when using Play framework with the AngularJS route extension. You must understand that Play route and Angular routes aren't interchangeable. Each of them play a different role in integration.
Client side navigation between views is done via Angular routing. It's responsible for serving the ng-view directive. This directive should be placed in a shell page in this case served by Play. It can be created as a static HTML file in Plays' public assets directory or dynamically generated from a Scala template and exposed via controller.
The same scenario goes for partial views displayed with the ng-view directive. They can be static HTML files in Plays' public assets directory or dynamically generated and initially populated with data. A bridge between them is Angular route definition. For example:
angular.module('AppModule', ['ngRoute'])
.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/feature', {templateUrl: '/playRoute/feature', controller: 'FeatureController'});
}]);
The route /feature corresponds to the client side URL part after # while /playRoute/feature is the server side URL which is exposed by Play to serve the view fragment.
Additionally you probably would like to use Play routes to define REST endpoints so your Angular app could use them to manipulate data via $http service.