I'm new to angular and having a hard time figuring out how to make it pull the most current data from the database when I refresh the page (shift+refresh). There were three records that existed in the database which get pulled and displayed how I intend, but I added three more records manually via heidisql then refresh the page and it still only shows the original three.
What can I do to remedy this situation? I want to make sure that it's always displaying the records that exist in the database.
I've only included the code that is relevant. If you need to see more, please let me know.
Note: After an hour or so of waiting it will finally grab the new data, but the problem still exists if I add another. I would like for it be in real time.
//Contents of app.js////////////////////////////////////////////////////////
var app = angular.module('unitTrackerApp', ['ngAnimate','ngCookies','ngResource','ngRoute','ngSanitize','ngTouch', 'xeditable', 'ui.bootstrap', 'httpPostFix']);
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.otherwise({
redirectTo: '/'
});
});
app.factory('myService', function($http, $q) {
var deffered = $q.defer();
var data = [];
var myService = {};
myService.async = function() {
$http.get('myphpfile')
.success(function (d) {
data = d;
deffered.resolve();
});
return deffered.promise;
};
myService.data = function() { return data; };
return myService;
});
//Contents of main.js://///////////////////////////////////////////////////
angular.module('unitTrackerApp')
.controller('MainCtrl', function (myService, $scope, $filter, $http) {
$scope.sortType = 'name';
$scope.sortReverse = false;
$scope.searchUnit = '';
var unitObj = new Array();
getUnits();
function getUnits(){
myService.async().then(function(){
var data = myService.data();
console.log('GET Call');
processData(data, unitObj);
});
}
function processData(data, unitObj) {
angular.forEach(data, function(obj, index) {
var stockNum;
if (obj.consign_flag === '1') {
stockNum = obj.unit_num += 'C';
} else {
stockNum = obj.unit_num;
}
unitObj[index] = {
id: obj.id,
dateAdded: new Date(obj.dateAdded),
unitCondition: obj.unitCondition,
make: obj.make,
model: obj.model,
unit_num: stockNum,
serial_num: obj.serial_num,
description: obj.description,
gl_num: obj.gl_num,
trade: obj.trade,
invoice_posted: obj.invoice_posted,
notes: obj.notes
};
}, unitObj);
$scope.units = unitObj;
console.log($scope.units);
}
});
Solved by editing .htaccess
<IfModule mod_headers.c>
<FilesMatch "\.(php)$">
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Expires "Thu, 1 Jan 2015 05:00:00 GMT"
</FilesMatch>
</IfModule>