I am utilizing a factory to access my server-side data, using $routeParams
to pass the id in the server request. Initially, everything functions correctly, but issues arise after the first run through the program. Here is a snippet of my code:
Controller:
klusplan.success(function(data) {
console.log("onsucces",data);
$scope.klusplan = data[0];
$scope.klusplan.duratie = localStorage.getItem('Duration');
$scope.klusplan.orderId = localStorage.getItem('klusplan');
var tijdInUren = localStorage.getItem('Duration').split(":");
var Uren = tijdInUren[0];
var Minuten = tijdInUren[1];
Uren = Uren + (Minuten / 60);
$scope.klusplan.kosten = ($scope.klusplan.vm_kl_tarief * Uren);
});
Service:
app.factory('klusplan', ['$http', '$routeParams', function($http, $routeParams) {
return $http.get('http://localhost:8080/getdata/klusplan.php?id='+$routeParams.klplan_id)
.success(function(data, status) {
console.log("succes", data, status);
return data;
})
.error(function(err) {
return err;
});
}]);
Route:
.when('/klusplan/:klplan_id', {
controller: 'KlusplanController',
templateUrl: 'views/klusplan.html'
})
I have attempted solutions such as:
$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
and
app.run(function($rootScope, $templateCache) {
$rootScope.$on('$routeChangeStart', function(event, next, current) {
console.log("event: ", event," next: ", next," current: ", current)
$templateCache.remove(current.templateUrl);
});
});
Upon revisiting the application, the issues arise. Instead of triggering a new http request to fetch data from the server, the application displays data from the previous run. Any assistance would be greatly appreciated.