I have two routes in a page wired up with Angular JS.
One page has a form from which you can save some information, angular seems to be not requesting for the html when I switch back and forth between the routes.
I have tried doing $httpProvider.defaults.cache = false;
Basically for one route I don't want Angular to be caching the html, for the other routes it is actually a good thing.
Code is given here:
angular.module('userAccount', ['ngRoute', 'ngAnimate'])
.config(['$routeProvider', '$locationProvider', '$httpProvider',
function ($routeProvider, $locationProvider, $httpProvider) {
//$httpProvider.defaults.cache = false;
$locationProvider.hashPrefix('');
$routeProvider
.when('/UserProfile/:action', {
reloadOnSearch: false,
cache: false,
templateUrl: function (params) {
return '/UserProfile/' + params.action;
},
controller: 'UserProfCtrl'
})
.when('/UserDashboard/:action', {
templateUrl: function (params) {
return '/UserDashboard/' + params.action;
},
controller: 'UserDashCtrl'
})
.otherwise('/UserDashboard/Index');
}])
.controller('MainCtrl', ['$scope', '$route', '$routeParams', '$location',
function ($scope, $route, $routeParams, $location) {
$scope.$on('$routeChangeStart', function (next, current) {
});
this.$route = $route;
this.$location = $location;
this.$routeParams = $routeParams;
}])
.controller('UserProfCtrl', ['$routeParams', function ($routeParams) {
this.name = "UserProfCtrl";
this.params = $routeParams;
}])
.controller('UserDashCtrl', ['$routeParams', function ($routeParams) {
this.name = "UserDashCtrl";
this.params = $routeParams;
}]);
Note that i have removed some unrelated ui manipulation code here.
I have same problem in my hybrid mobile app and resolved by adding cache: false in my route.js
$stateProvider.state('stateName', {
cache: false,
url : '/url',
templateUrl : 'template.html'
})
Hope it will resolve your problem as well.
you can try to add query string with url
return '/views/' + params.action+'?'+$.now();
I know its late but it may help someone
I just used this before my routes and it worked.
myApp.run(function($rootScope, $templateCache) {
$rootScope.$on('$viewContentLoaded', function() {
$templateCache.removeAll();
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With