The main goal is to return some JSON data with Angular from a Java servlet. So, I have a factory DispatcherService
where I'm getting my resource key:
cfdb.tasks.primite.list=/task/received_task.do?method=list&cleanSess=1&json=true
In my Chrome console I get this:
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
But I don't know why I can`t access objects from my 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>
Ok, now I see I bounded my $scope
with the debug message for no reason: $scope.todos = $log.debug("tasks data",data);
Solution:
1) $scope.todos = data;
2) <p ng-repeat="task in todos track by $index">{{task.receivedTasksList}}</p>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.