Thursday, 15 March 2012

angularjs - How to get JSON from JSP and insert it into Angular's Model? -


I am new to Anguluj and Javascript and now I am trying to create a Java object and I convert it to JSON Have given. Then I try to capture this JSON with an angle controller and display it as an angular model, but now when I run my application, I can not find my Jasonson in my browser. I have a simple code in my JSP:

  & lt; Html data-ng-app = "mathsApp" & gt; & Lt; Top & gt; & Lt; Title & gt; Calculus race & lt; / Title & gt; & Lt; Meta charset = "UTF-8" & gt; & Lt; Meta name = "viewport" content = "width = device-width, initial-time = 1.0" & gt; & Lt; Script src = "js / angular.js" & gt; & Lt; / Script & gt; & Lt; Script src = "js / controllers.js" & gt; & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt;% car vago = new car (1500, 6); Org.json.JSONObject jso = New JSONObject (); Jso.put ("vago", vago); & Gt%; & Lt ;! - This line works fine - & gt; & Lt; P data-ng-controller = "moncunt" & gt; {{Temps}} & lt; / P & gt; & Lt ;! - This line does not work, here I am trying to get my JSON - & gt; & Lt; P data-ng-controller = "moncunt" & gt; {{Test}} & lt; / P & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

and my controller:

  var math app = angular.module ('mathsApp', []); MathsApp.controller ('monControl', function ($ radius, $ http) {$ scope.temps = 'pluie'; $ scope.test = http.get ("http: // localhost: 8080 / Angular_on_JEEE / index.jsp ") .success (function (data) {$ scope.names = data;});});  

Please, someone can tell me what is wrong here? Thanks in advance and sorry for my english but I love this awesome community.

I think your second line should be printed

 < Code> & lt; P data-ng-controller = "moncunt" & gt; {{Name}} & lt; / P & gt;   

Because you are accumulating the variable in test in name ( in the success of the controller )> .


No comments:

Post a Comment