angularjs - Angular - getting data with a factory -
i'm modifying way app gets it's data.
the app got data on page load this
<script> var entries = <?php echo $this->entriesdata; ?>; </script>
and in angular controller
$scope.entries = entries;
requirements changed user able go forward or backward 1 week added factory app supposed load data when page loads , refresh data when changeweek() fired. according console factory (loaddata) fires when page loads , again on changeweek() , data comes down server expected. problem view doesn't display data. i'm assuming i'm not returning data $scope.entries correctly. please!
var timeentry = angular.module('timeentry', ['ui.select2']); timeentry.factory('loaddata', function($http){ var url = 'index/getentries'; var returndata = ''; var factory = {}; factory.getdata = function(sdate, edate){ $.post(url, {week_start: sdate, week_end: edate}) .done(function(json, textstatus){ if (textstatus === 'success') { returndata = json; }else{ // handle fail } }) .fail(function(){}) .always(function(){}); return returndata; }; return factory; }); timeentry.controller('timeentrycontroller', ['$scope','loaddata', function ($scope, loaddata) { $scope.loading = true; $scope.date = []; $scope.date.start = startdate; $scope.date.end = enddate; $scope.entries = loaddata.getdata($scope.date.start, $scope.date.end); $scope.weektotal = 0; $scope.timeentryerror = []; $scope.$watch('entries', function(newnames, oldnames) { $scope.datacount = newnames.length; $scope.timeentryerror = []; calculatetotals(); checkdayhours(); checkspecialdays(); }, true); $scope.changeweek = function(change) { sdate = moment($scope.date.start); edate = moment($scope.date.end); $scope.date.start = sdate.add(moment.duration(change, 'week')).format('yyyy-mm-dd'); $scope.date.end = edate.add(moment.duration(change, 'week')).format('yyyy-mm-dd'); $scope.entries = loaddata.getdata(); }; }]);
Comments
Post a Comment