Angularjs 如何在angular中更新缓存的get请求
我只是想知道如何以及在哪里使用$watch更新通过http get请求和cache:true选项收到的数据Angularjs 如何在angular中更新缓存的get请求,angularjs,watch,Angularjs,Watch,我只是想知道如何以及在哪里使用$watch更新通过http get请求和cache:true选项收到的数据 服务: app.factory('customer', ['$http',function($http){ var obj = {}; var baseUrl="../controller/customer.php"; obj.fetchCustomers= function(){ var config={ cach
服务:
app.factory('customer', ['$http',function($http){
var obj = {};
var baseUrl="../controller/customer.php";
obj.fetchCustomers= function(){
var config={
cache: true
}
return $http.get(baseUrl +'?type=getAll',config);
}
obj.editCustomer=function(customerInfo){
return $http.post(baseUrl,{data:customerInfo ,type:'edit'});
}
return obj;
}]);
接收数据的控制器:
customer.fetchCustomers().success(function(data){
$rootScope.customers=data.getAll;
})
编辑数据的控制器:
$scope.editCustomer=function(){
customer.editCustomer($scope.customerInfo).success(function(data){
if(data.error=true){
$location.path("/accounting/viewCustomer");
}else{
$scope.alert="wrong";
}
})
};
它工作正常,但当我更新数据时,我的视图不会更新现在还不清楚您在这里遇到了什么问题。如果您在更新视图时遇到问题,我们需要查看视图以帮助解决问题。除此之外,为什么当出现错误时,您的
editCustomer
回调会重定向您,并在没有错误时告诉您它是“错误的”?那没有多大意义。另外,您应该使用.then()
而不是.success()
,因为.success()
已被弃用。我的问题是,当editcontroller更新数据库时,视图仍显示chachedright以前的数据,这一点很清楚,但我们不知道该视图为什么显示任何数据,因为我们这里没有视图代码。视图中没有逻辑,只有一个ng在$rootScope.customers objectok中重复该循环,但您没有使用editCustomer
函数更改$rootScope.customers
对象,那么,该函数将如何更新$rootScope.customers
数据的视图呢?现在还不清楚您遇到了什么问题。如果您在更新视图时遇到问题,我们需要查看视图以帮助解决问题。除此之外,为什么当出现错误时,您的editCustomer
回调会重定向您,并在没有错误时告诉您它是“错误的”?那没有多大意义。另外,您应该使用.then()
而不是.success()
,因为.success()
已被弃用。我的问题是,当editcontroller更新数据库时,视图仍显示chachedright以前的数据,这一点很清楚,但我们不知道该视图为什么显示任何数据,因为我们这里没有视图代码。视图中没有逻辑,只有一个ng在$rootScope.customers objectok中重复该循环,但您没有使用editCustomer
函数更改$rootScope.customers
对象,那么该函数如何更新$rootScope.customers
数据的视图?