-1

I have an application with AngularJS on top of Play frameework. Want to use Play framework for services only. How do I make my angularjs routing work? My applicaton is always looking into in Play routes and never looks into Angularjs routes and so gives an error that route is not found.

I saw some examples in scala. didn't quite understand what they are doing.

Play Routings:

POST /location @controllers.Application.create()

GET /location/:id @controllers.Application.get(:Id)

GET / @controllers.Application.list()

AngularJS Routings:

config(['$routeProvider', '$locationProvider',
           function($routeProvider, $locationProvider) {
        console.log('In routeProvider()'+Date.now());
              $routeProvider.
                  when('/', {
                                 templateUrl: 'html/test.html',
                                 controller: 'LocationsController'
                 }).
                   when('/location/:id', {
                                 templateUrl: 'html/test.html',
                                 controller: 'LocationController'
                 }).
                  when('/locations', {
                                 templateUrl: 'html/test.html',
                                controller: 'LocationsController'
                });
        console.log('In routeProvider()..2'+Date.now());
               $locationProvider.html5Mode(true); // .hashPrefix("!")
      }])

For example, I want http://localhost:9000/ should hit Angularjs routings first. Angularjs controller will go get the data by requesting play service. Similarly, http://localhost:9000/location/100 needs to hit Angularjs first. Corresponding angularjs controller will get the data for that given id by requesting play's /location/100.

My applicaton is always looking into in Play routes and never looks into Angularjs routes and so gives an error that route is not found. How do I make both of them working? Thanks for any help.

Shiva Kodityala
  • 105
  • 1
  • 10

1 Answers1

0

I would suggest you, instead of having the Angular JS with play project, you would get rid of Angular JS as seperate app (you can use express as the server top of Node), and make any REST calls using $ngResource or Ajax call using $http in Angular, then serve the response from Play framework.

I had also searched lot of projects to integrate Angular with play, yet i did not find good one to go.

Note: You need to enable the CORS in Play server using Action composition to allow the Angular app to interact with Play server http://playframework.wiki/index.php?title=Access-Control-Allow-Origin

Sivailango
  • 544
  • 1
  • 6
  • 15
  • Hey, I am also thinking in the same way, that will make UI and services independent. I want to hear more suggestions from others too. – Shiva Kodityala May 18 '15 at 12:11