mongodb - Data not displaying in html file because of some angularjs issue -
i have display data mongodb database using spring , angularjs. data being fetched service.js method of angular js not displaying html file not returning 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 getting in chrome console : //inside controller: undefined //inside service method[object object],[object object]
you factory method should return $http promise using .then promise chain continue in controller
factory.gettask = function() { return $http.get('usernotification/fetchtaskforapproval').then(function(response) { //photos = response.data; taskdetails = response.data; console.log('inside service method'+taskdetails); return taskdetails; }); }; then controller method be
function init() { usernotificationservice.gettask().then(function(data){ //$scope.photos = data; $scope.taskdetails = data; }); console.log('inside controller: '+$scope.taskdetails); }
Comments
Post a Comment