2

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);
        });
    }]);
3
  • 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. Commented Jan 20, 2015 at 20:03
  • can you see a request being queued, on network tab of dev tools? Commented Jan 20, 2015 at 22:46
  • no in network tab request is not queued.. its loading the cached results Commented Jan 21, 2015 at 7:04

1 Answer 1

-1

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'
      }
    }
  })
Sign up to request clarification or add additional context in comments.

2 Comments

In UI-Router APi doesn't appear parameter cache. Anyway, I've tried and the solution not working.
as state by @robBerto 'cache' property does not available on ui-router api. tested and confirm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.