I have a list of customers on my DB who all joined at different years. I have configured my api to suit this and works fine. And my code with Angularjs works in pulling in the right data, only problem because it is the same route eg /customers/:id it doesnt refresh the data, it does refresh it if i manually refresh the browser. Any help will be great.
HTML links
<table>
<tr><td><a href="#customers/2014">2014</a></td></tr>
<tr><td><a href="#customers/2013">2013</a></td></tr>
<tr><td><a href="#customers/2012">2012</a></td></tr>
</table>
App.js (sample of where its called)
.when("/Archive/:param/", {
templateUrl: "Customers/Customers.html",
controller:"CustomersController"
})
CustomersController
(function () {
var CustomersController = function ($scope, customerService, $log, $routeParams, $location, $sce) {
var param = $routeParams.param;
var customer = function (data) {
$scope.Customer= data;
};
var errorDetails = function (serviceResp) {
$scope.Error = "Something went wrong ??";
};
var refresh = function () {
customerService.customer(param)
.then(customer, errorDetails);
};
refresh();
};
app.controller("CustomersController", ["$scope", "customerService", "$log", "$routeParams", "$location", "$sce", CustomersController]);
}());
CustomerService.js
(function () {
var customerService = function ($http, $q, $log, $scope) {
var cachedCustomer;
var customer = function (param) {
var params = param;
console.log("this is the "+params);
if (cachedCustomer)
return $q.when(cachedCustomer);
return $http.get("http://localhost:8080/api/customers/year/" + params)
.then(function (serviceResp) {
$log.info(cachedCustomer);
cachedCustomer = serviceResp.data;
$log.info(cachedCustomer);
return serviceResp.data;
});
};
return {
customer: customer,
};
};
var module = angular.module("CustomerModule");
module.factory("customerService", ["$http", "$q", "$log", customerService]);
}());
if (cachedCustomer) return $q.when(cachedCustomer);