title: Not able to access Spring model attribute in javascript
body: <p>I am trying to access a Spring Model attribute from js and html. 
  I have followed the below link and tried everything it said, but I keep getting errors:<br>
  <a href="https://stackoverflow.com/questions/9361977/how-to-access-model-attribute-in-javascript/22487897#22487897">How to access model attribute in Javascript</a></p>
  
  <p>This is the code which I have:   </p>
  
  <pre><code>     MyVOClass.java  
  
       private String id; 
       private String name; 
       //getters setters here 
  
       MyController.java 
       @RequestMapping(value = "/Display", method = RequestMethod.GET, headers 
        = "Accept=text/html")
        public String Display(@RequestParam(value = "id", required = true) 
        String id, @RequestParam(value = "name", required = true) String name, 
         Model model) {
  
        //set the values to the VO Object 
        MyVOClass myVo = call to another class to set the values 
        model.addAttribute("myVo ", new Gson().toJson(myVo));
  
        return "html page name "; 
  
  
        Js file: 
        var ID = JSON.parse('${myVo.id}');  
  </code></pre>
  
  <p>I am getting the below error on the console:</p>
  
  <pre><code>     angular.js:14525 SyntaxError: Unexpected token $ in JSON at position 0
       at JSON.parse (&lt;anonymous&gt;)
  </code></pre>
  
  <p>EDIT 2: </p>
  
  <p>If I try </p>
  
  <pre><code>      var ID = JSON.parse(${myVo.id}); 
  </code></pre>
  
  <p>I get the following error: </p>
  
  <pre><code>      Uncaught SyntaxError: missing ) after argument list
        Uncaught Error: [$injector:modulerr]  
  </code></pre>
  
  <p>Im not sure what am I missing? Do i need any additional config in my js and html to access Model? </p>
  
  <p>EDIT 1: </p>
  
  <p>Adding my Java API code as well:   </p>
  
  <pre><code>     @RequestMapping(value = "/display", method = RequestMethod.GET, headers 
       = "Accept=text/html")
       public String display(@RequestParam(value = "param1", required = true) 
       String param1, Model model) {
  
      String html = "/view";
      MyVo myVo = new MyVo();
      //set data 
  
      Gson gson = new Gson();
      String respJson = gson.toJson(authresp);
  
      String respstr = authrespJson.toString();
      model.addAttribute("myVo ", respstr );
      System.out.println("response Json string "+respstr );
  
      return html;
      }
  </code></pre>