如何从java servlet返回带有角度的JSON数据?

时间:2015-07-29 10:30:35

标签: java json angularjs

主要目标是从Java servlet返回一些带有Angular的JSON数据。 所以,我有一个工厂DispatcherService我正在获取我的资源键:

cfdb.tasks.primite.list=/task/received_task.do?method=list&cleanSess=1&json=true

在我的Chrome控制台中,我得到了这个:

tasks data Resource { SESSION_ATTRIBUTES: Object, REQUEST_PARAMETERS: Object,
REQUEST_ATTRIBUTES: Object, $promise: Promise, $resolved: true} $promise: Promise$resolved: true REQUEST_ATTRIBUTES: Object REQUEST_PARAMETERS: ObjectSESSION_ATTRIBUTES: Object__proto__: Resource
tasksCtrl.js:42

但我不知道为什么我不能从我的JSON访问对象。

.factory('DispatcherService', ['$resource', '$location', 'UrlService', function ($resource, $location, UrlService) {
    var contextPath = UrlService.getContextPath();

    return $resource('', {}, {
        getResource: {url: contextPath + '/rest/dispatch', method: 'GET', isArray: false},
        getArray: {url: contextPath + '/rest/dispatch', method: 'GET', isArray: true},
        invalidateSession: {url: contextPath + '/rest/invalidate/session', method: 'GET', isArray: false},
        downloadFile: {url: contextPath + '/rest/download/file', method: 'GET', isArray: false},
        postResource: {url: contextPath + '/rest/dispatch', method: 'POST', isArray: false}
    });
}])

.controller('TasksCtrl', ['$scope', 'DispatcherService', 'HideHeadersService', '$location', '$log', '$http',
function ($scope, DispatcherService, HideHeadersService, $location, $log, $http) {

DispatcherService.getResource({
  key: 'cfdb.tasks.primite.list'

}, function success(data) {
  $scope.todos = data; //edited
  $log.debug("tasks data",data);
  console.log("break and my code: ");

}, function error(data) {
  // $scope.pagination.loading = false;
  $log.debug("ERROR - getTabResource", data.REQUEST_ATTRIBUTES);
  if (data.status && data.status == 401)
    $location.path("/login");
});
}])

HTML

<div ng-controller="TasksCtrl">
   <p ng-repeat="task in todos track by $index">{{task.receivedTasksList}}</p> //edited
</div>

1 个答案:

答案 0 :(得分:0)

好的,现在我看到我无条件地使用调试消息限制了$scope$scope.todos = $log.debug("tasks data",data);

解决方案:

1) $scope.todos = data;
2) <p ng-repeat="task in todos track by $index">{{task.receivedTasksList}}</p>