1

I am trying to pass list of java objects to angularjs variable so I can use their properties in html like {{object.name}}. I run angularjs function from script like

    angular.element("get angularjs controller element").scope().myfillingFunction(javaObjectsList)

And in angularjs i have method 

    $scope.myfillingFunction = function(list){
        console.log("input: "+list)
        $scope.productList=list;
    }

In console i can see only

"Input:"

3
  • Why not just $scope.myfillingFunction(javaObjectsList) ? Commented Jun 9, 2017 at 7:54
  • How are you passing this java objects, Rest API? Are you sure you have correct response from the server? Commented Jun 9, 2017 at 7:55
  • Well i'm passing it to request parameter and i'm sure i have correct response because in my freemarker template i display 'javaObjectsList[0].name' and it's works. In my Java Controller i have request.setParameter("param", javaObjectsList) Commented Jun 9, 2017 at 8:05

1 Answer 1

1

You can convert the Java object to JSON by encoding it using the Gson library and decoding it back in Angular.

Java to JSON String

List<MyObject> objList = new List<MyObject>();
String objJSON = new Gson().toJson(objList);

JSON to JS Object

<script>
  var jsObject = angular.fromJson(<%= objJSON %>);
</script>
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.