0

First, I want my mode.addAttribute() object to be accessed into ng-repeat.

My requirement is, on landing page I want to show list of Departments and this object will be added in Spring MVC (i.e. ModelAndView.getAttribute).

I can be able to achieve it ${departmentsList} by iterating it like below:

<select>
  <c:forEach items="${departmentsList}" var="department">
    <option value="${department.name}"> ${department.name}
    </option>
  </c:forEach>
</select>

But I am looking for better approach something like this:

<select ng-model="department" ng-options="department.name for department in departmentsList"></select>

but somehow I am not able to access departmentsList into the ng-options.

How can I achieve this?

1 Answer 1

1

Spring MVC process the JSP file on server side and have access to ModelAndView object. Whereas, AngularJS runs on client side and doesn't have access to ModelAndView object.

You can do a workaround by assigning the ModelAndView data to a JavaScript variable and assign it to $scope in controller.

JSP file

<script>
var tempDepartmentsList = ${departmentsList}
</script>

AngularJS controller

app.controller("yourController", function($scope) {
  $scope.departmentsList = tempDepartmentsList;
});

Now you should be able to iterate the departmentsList using AngularJS ng-repeat.

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.