0

I having trouble dealing with angularjs.

My code is like this:

$routeProvider

.when('/chart/pie',{
    templateUrl : 'chart/pie'
})

ChartController

public ModelAndView getChart(){
   ModelAndview mv = new ModelAndView();

   mv.setView("chart");

   mv.addObject("user", User);

   return mv;
}

chart.html

result : {{user}}

I would guessed I received [ result : {'name': 'haha', 'age' : '17'}] but result was: [result : {{user}} ]

How can I get the preferred result?

1 Answer 1

1

You need to return the User (not the model and view object), and need to add the ReponseBody annotation

@ResponseBody
public User getChart(){
    User user = ....
    return user;
}

Hint: from the Spring point of view, this problem has nothing to to with AngularJs, but sending a JSON response. So if you have more problems, that search for Spring and Json (a simple example can be found here).

Sign up to request clarification or add additional context in comments.

Comments

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.