У меня есть список клиентов моей БД, которые все присоединились в разные годы. Я настроил api для этого и отлично работает. И мой код с Angularjs работает в поиске правильных данных, только проблема, потому что это тот же маршрут, например/clients /: id, он не обновляет данные, он обновляет его, если я вручную обновляю браузер. Любая помощь будет отличной.Обновление данных на AngularJs
HTML ссылки
<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 (образец, где его называют)
.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]);
}());
Может быть, это из-за этого: 'если (cachedCustomer) вернуть $ q.when (cachedCustomer);' –
Эй, я удалил эту строку кода на данный момент, и он работает :) Спасибо за указание, где находится проблема :) – georgieboy