go()不刷新数据

时间:2020-12-25 19:40:00

I have a Product List state and Product Edit/Add state in my Angular app.

我有一个产品列表状态和产品编辑/添加状态在我的角应用。

Product List data gets loaded in the controller (I didn't think I need resolve to be defined in state config) which gets data from an ngResource:

产品列表数据被加载到从ngResource获取数据的控制器(我不认为我需要在状态配置中定义解析):

function InventoryListCtrl (myResource) {
  var vm = this;

  myResource.query(function (data) {
    vm.products = data;
  });
}

On Edit Controller, after I edit a product I get back to list state like this:

在编辑控制器上,当我编辑一个产品后,我回到列表状态如下:

vm.product.$update().$promise;
$state.go('productList');

It doesn't load list with new data always, it shows old data in first run generally, then after I do second update and manually get back to list state it starts to refresh after each update.

它不总是用新数据加载列表,它通常在第一次运行时显示旧数据,然后在我进行第二次更新并手动返回列表状态后,每次更新后就开始刷新。

I've tried this, but didn't work either:

我试过了,但也没用:

vm.product.$update().$promise;
$state.go('productList', {}, { reload: true });

What am I missing?

我缺少什么?

3 个解决方案

#1


79  

I think you're loading the new state before the update has completed - try moving the state transition to after the update completion:

我认为您正在加载更新完成之前的新状态—尝试将状态转换移动到更新完成之后:

vm.product.$update().then(function(){
  $state.go('productList', {}, { reload: true });
});

#2


13  

i think this should work for current state refresh.

我认为这应该用于当前状态刷新。

$state.go($state.current, {}, {reload: true}); //second parameter is for $stateParams

#3


3  

I had the same problem with a list not refreshing after edit. Wrapping the $state.go in a $timeout function solved my problem.

我有同样的问题,在编辑后没有刷新的列表。包装的状态。使用$timeout函数解决了我的问题。

$timeout(function(){
    $state.go('publishers.list', {}, { reload: true });
},200);

#1


79  

I think you're loading the new state before the update has completed - try moving the state transition to after the update completion:

我认为您正在加载更新完成之前的新状态—尝试将状态转换移动到更新完成之后:

vm.product.$update().then(function(){
  $state.go('productList', {}, { reload: true });
});

#2


13  

i think this should work for current state refresh.

我认为这应该用于当前状态刷新。

$state.go($state.current, {}, {reload: true}); //second parameter is for $stateParams

#3


3  

I had the same problem with a list not refreshing after edit. Wrapping the $state.go in a $timeout function solved my problem.

我有同样的问题,在编辑后没有刷新的列表。包装的状态。使用$timeout函数解决了我的问题。

$timeout(function(){
    $state.go('publishers.list', {}, { reload: true });
},200);