我尝试在POST请求后将$ state.reload放入我的控制器中,但它不会刷新我的页面。因此,在我注册表单后,我的页面上的数据没有更新。我不得不手动刷新,以便向我显示正确的数据。
.controller('editCtrl', function($scope, $stateParams, $state, AppService) {
$scope.infos = AppService.getObject();
console.log($scope.infos);
AppService.user($scope.infos).then(function(response){
$scope.user = response;
console.log($scope.user);
});
$scope.save = function (currObj) {
AppService.edituser($scope.form,$scope.infos).then(function(response){
AppService.addObject(currObj);
console.log(currObj);
$state.reload('menu.infosUser');
$ionicLoading.hide();
$state.go('menu.infosUser',{reload: true});
});
};
})
我会尽快回复所有提案:)
答案 0 :(得分:1)
如果您确实要重新加载页面,请使用location.reload()
重新加载页面,如
.controller('editCtrl', function($scope, $stateParams, $state, AppService) {
$scope.infos = AppService.getObject();
console.log($scope.infos);
AppService.user($scope.infos).then(function(response){
$scope.user = response;
console.log($scope.user);
});
$scope.save = function (currObj) {
AppService.edituser($scope.form,$scope.infos).then(function(response){
AppService.addObject(currObj);
console.log(currObj);
location.reload();
});
};
})
或者您可以仅使用$state.go('menu.infosUser',{reload: true});
重新加载您的状态,它会清除您的缓存数据,例如
.controller('editCtrl', function($scope, $stateParams, $state, AppService) {
$scope.infos = AppService.getObject();
console.log($scope.infos);
AppService.user($scope.infos).then(function(response){
$scope.user = response;
console.log($scope.user);
});
$scope.save = function (currObj) {
AppService.edituser($scope.form,$scope.infos).then(function(response){
AppService.addObject(currObj);
console.log(currObj);
$ionicLoading.hide();
$state.go('menu.infosUser',{reload: true});
});
};
})