I have to display some data from mongodb database using spring and angularjs. Data is being fetched to service.js method of angular js but its not displaying into html file as its not returning to controller.
UserNotification.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<!-- <h2>Approve/Reject Pending Task</h2> -->
<div class="row">
<table class="table table-bordered">
<thead>
<tr>
<th style="text-align: center;">Task name</th>
<th style="text-align: center;">Owner name</th>
<th style="text-align: center; width: 25px;">Approve</th>
<th style="text-align: center; width: 25px;">Reject</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="task in taskDetails">
<td>{{task.name}}</td>
<td>{{task.owners.ownerName.id}}</td>
<td style="width:70px;text-align:center;"><button class="btn btn-mini btn-primary" ng-click="approveTask(taskDetails.indexOf(task), task)">Approve</button></td>
<td style="width:70px;text-align:center;"><button class="btn btn-mini btn-danger" ng-click="rejectTask(taskDetails.indexOf(task), task)">Reject</button></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
controller.js
releaseApp.controller('UserNotificationController', function($scope, $location, $http, UserNotificationService) {
$scope.taskDetails = [];
init();
function init() {
$scope.photos = UserNotificationService.getTask();
console.log('inside controller: '+$scope.taskDetails);
}
});
service.js
releaseApp.factory('UserNotificationService', function($http){
var taskDetails = [];
var factory = {};
factory.getTask = function() {
$http.get('userNotification/fetchTaskForApproval').success(function(data, status, headers, config) {
photos = data;
console.log('inside service method'+taskDetails);
return taskDetails;
});
};
return factory;
});
// response i am getting in chrome console :
//inside controller: undefined
//inside service method[object Object],[object Object]