title: Getting data from Spring MVC in Angular JS in the initial view call
body: <p>I am new to Angular JS, I have created a Spring MVC web application with Angular JS, I know that from view we can call REST services from Angular JS using resource, restangular, http , But say in Spring form the Controller a view is been triggered and for loading the datas through angular within the view again a REST call from angular is been called from view to the server and gets the datas thereafter for loading, Instead is there any way to pass the json object while triggering the view from Spring controller to the Angular JS at the first time itself.</p>
  
  <p><img src="https://i.stack.imgur.com/Ct4j4.png" alt="enter image description here"></p>
  
  <p>I have done a similar thing, its working fine but don't know whether its a good approach or not.</p>
  
  <p><strong>Spring controller</strong></p>
  
  <pre><code>@RequestMapping("/getemployee")
  public ModelAndView helloWord(){
     JSONArray employeeJsonArray = // contains all the information of the employee
     return new ModelAndView("employee", "employee",employeeJsonArray);
  }
  </code></pre>
  
  <p><strong>employee.jsp</strong></p>
  
  <pre><code>&lt;html ng-app="myApp"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Spring 3.0 MVC Series: Hello World&lt;/title&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  var app = angular.module('myApp', []);
  app.controller('MyCtrl', function($scope) {
      $scope.employee = [];
      $scope.loadData = function(employee)
      {
          $scope.employee = JSON.parse(employee);
      };
  });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body ng-controller="MyCtrl"&gt;
  {{loadData('${employee}')}}
  
   &lt;input type="text" ng-value="employee[0].name"/&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>