【问题标题】:AngularJS ui-router ui-sref giving cached resultsAngularJS ui-router ui-sref 提供缓存结果
【发布时间】:2015-03-19 04:34:40
【问题描述】:

我的项目是关于创建帖子的。成功创建帖子后,页面将被重定向到帖子显示页面。在帖子显示页面中,给出了帖子索引的链接。我正在使用 ui-sref 指令进行重定向。

我面临的问题 - 重定向回索引页面后,新帖子未显示。该页面被缓存并显示旧结果。我需要重新加载页面并获取所有结果

我在 $http 中添加了 cache : false 选项但没有成功

代码

路线

.state('main.tabs.dash', { 网址:'/破折号', 意见:{ '制表符':{ templateUrl: 'views/tab-dash.html', 控制器:'PostsCtrl' } } })

查看

<a ui-sref="main.tabs.dash">back to Index</a>

控制器

'use strict';
myApp.controller('PostsCtrl', ['$scope', '$http', '$location', 'Auth', '$state', '$rootScope', 'registrationData', function ($scope, $http, $location, Auth, $state, $rootScope, registrationData) {
        $scope.posts = {};
        $http({
            url: $rootScope.url + '/posts',
            method: 'GET',
            cache: false,
            params: {
                user_email: xxxx,
                user_token: xxxx
            },
            headers: {
                'Authorization': 'Token token=' + xxxx,
                'Accept': 'application/json'
            }
        }).success(function (data) {
            $scope.posts = data;
        }).error(function (error) {
            console.log(error);
        });
    }]);

【问题讨论】:

  • 我可以直接建议的一件事是,您可以查看 ui-router 的 resolve 获取状态数据的功能。
  • 您能在开发工具的网络选项卡上看到正在排队的请求吗?
  • no in network tab request is not queued.. 它正在加载缓存的结果

标签: angularjs angular-ui-router


【解决方案1】:

您可以在routes中将属性cache: false添加到状态配置中。 从您的示例开始进入路线:

.state('main.tabs.dash', {
    url: '/dash',
    cache: false,
    views: {
      'tab-dash': {
        templateUrl: 'views/tab-dash.html',
        controller: 'PostsCtrl'
      }
    }
  })

【讨论】:

  • UI-Router APi 中没有出现参数缓存。无论如何,我已经尝试过,但解决方案不起作用。
  • @robBerto 'cache' 属性的状态在 ui-router api 上不可用。测试并确认
猜你喜欢
  • 2019-03-22
  • 2014-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-30
  • 2015-03-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多