2
votes

My project is about posts creation. On successfull creation of post, page will be redirected to post show page. In the post show page a link to posts index is given. I'm using ui-sref directive for redirection.

Issue I'm facing- after redirecting back to index page the new posts are not showing up. the page is cached and showing old results. I need page to be reloaded and fetch all results

i have added cache : false option in $http but no success

code

routes

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

view

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

controller

'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);
        });
    }]);
1
One thing I can suggest right off the top is that you look at ui-router's resolve functionality for fetching data for a state. - JAAulde
can you see a request being queued, on network tab of dev tools? - André Werlang
no in network tab request is not queued.. its loading the cached results - user1980065

1 Answers

-1
votes

You can add the attribute cache: false to the state configuration in routes. Starting from your example into routes:

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