Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Ionic-单击“上一步”按钮时重新加载并以ng重复显示新数据 背景_Angularjs_Angularjs Ng Repeat_Ionic Framework_Angularjs Routing_Ionic - Fatal编程技术网

Angularjs Ionic-单击“上一步”按钮时重新加载并以ng重复显示新数据 背景

Angularjs Ionic-单击“上一步”按钮时重新加载并以ng重复显示新数据 背景,angularjs,angularjs-ng-repeat,ionic-framework,angularjs-routing,ionic,Angularjs,Angularjs Ng Repeat,Ionic Framework,Angularjs Routing,Ionic,我有一个ng repeat列表,它会转到一个详细信息页面(有一个后退按钮)。$scope.items变量是通过myrefreshItems()函数从第一次加载页面时发生的get请求加载的 问题 单击“详细信息”页面上的“上一步”按钮时,您将返回到正确的页面,但列表未刷新。我需要刷新此列表,以便加载和显示新项目 尝试解决方案 我想我可以简单地将Back按钮连接到一个ng click函数,该函数使用ionichistore返回,然后调用我的refreshItems()函数;但是,这不会重新加载第一页

我有一个
ng repeat
列表,它会转到一个详细信息页面(有一个后退按钮)。
$scope.items
变量是通过my
refreshItems()
函数从第一次加载页面时发生的get请求加载的

问题 单击“详细信息”页面上的“上一步”按钮时,您将返回到正确的页面,但列表未刷新。我需要刷新此列表,以便加载和显示新项目

尝试解决方案 我想我可以简单地将Back按钮连接到一个
ng click
函数,该函数使用
ionichistore
返回,然后调用我的
refreshItems()
函数;但是,这不会重新加载第一页上的项目

上面的尝试确实返回到最后一页并触发
refreshItems()
函数(并且加载了新数据,这要感谢
console.log()
语句),但我猜ng重复需要重新生成。我找到了有关
$scope.$apply()
以及
$route.reload()
的一些信息,但当我将它们放在
goBack()
函数的末尾时,它们都没有解决问题

代码摘录 controller.js

$scope.refreshItems = function() {

    console.log("Refreshing items!");

    $http.get('http://domain/page.aspx').then(function(resp) {
        $scope.items = resp.data; console.log('[Items] Success', resp.data);
    }, function(err) { console.error('ERR', err); });

};


$scope.goBack = function() {
    $ionicHistory.goBack();
    $scope.refreshItems();
};
主页HTML

<div class="list">

    <a ng-repeat="i in items" class="item" href="#/tab/details?ID={{i.Item_ID}}">
        <b>Item {{i.Item_Name}}</b>
    </a>

</div>

详细信息页面上的后退按钮

<ion-nav-bar>
    <ion-nav-back-button class="button-clear" ng-click="goBack();">
        <i class="ion-arrow-left-c"></i> Back
    </ion-nav-back-button>
</ion-nav-bar>

返回

可能的方向? 我在主页上有一个
刷新器
,它调用
refreshItems()
——并正确刷新它们。当我尝试将刷新与
$ionichistore.goBack()
$state.go()
配对时,问题肯定会出现。有没有一种方法可以通过编程方式调用Refresh(加载后/加载时),因为直接调用Refresh调用的函数不起作用;按如下方式防止缓存:

cache-view="false"
$stateProvider.state('mainPage', {
   cache: false,
   url : '/dashboard',
   templateUrl : 'dashboard.html'
})
例如:

<ion-view view-title="Title" cache-view="false">

我想出了一个解决方案

解决方案是使用(“$stateChangeSuccess”)上的
$scope.$on
函数。使用函数参数检查“收件人/发件人”视图,或使用
$location.path()


ionicConfigProvider
中设置缓存标志。禁用状态提供程序中的缓存,如下所示:

cache-view="false"
$stateProvider.state('mainPage', {
   cache: false,
   url : '/dashboard',
   templateUrl : 'dashboard.html'
})

有关详细信息,请参阅。

您还可以从详细信息页面广播事件,并在列表控制器中侦听此事件


如果这被标记为一个错误,我不会感到惊讶。如果您解释您的解决方案并包含相关的代码片段,将对社区有更大的帮助。