0

im using spring mvc with angular js. i would like to know if there's a way to use angularjs router instead using spring mvc router?

//Java

@RequestMapping(value = "cases", method = RequestMethod.GET)
public String showCase() {
    return "case/cases";
}


//angular
app.angular.config([ '$routeProvider', function($routeProvider) {
    $routeProvider.when('/login', {
        controller : 'UserController',
        templateUrl : 'login.html'
    }).when('/case', {
        controller : 'CaseController',
        templateUrl : 'case/cases.html',
     })

} ]);

1 Answer 1

1

If you want to use angularjs routing features, you need to design restful api with spring. Your controllers should return json data that can be easily consumed by angularjs.

3
  • Thank you! do i need to map the view in java controller?@RequestMapping(value = "cases", method = RequestMethod.GET) public String showCase() { return "case/cases"; } Commented Aug 27, 2014 at 10:17
  • You will need to map requests to your controller (through [@RequestMapping]) and you would not be returning view names. You should probably look at [@RestController] and [@ResponseBody] annotations for more information. Also have a look at the spring io guide spring.io/guides/gs/rest-service Commented Aug 27, 2014 at 12:47
  • 1
    I'll always get error 404 on browser but when i map the view names in java controller it works. Commented Aug 28, 2014 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.