我在与Angular JS连接的页面中有两条路由.
一个页面有一个表单,您可以从中保存一些信息,当我在路由之间来回切换时,angular似乎没有请求html.
我试过做$ httpProvider.defaults.cache = false;
基本上对于一条路线我不希望Angular缓存html,对于其他路线它实际上是一件好事.
代码在这里给出:
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;
}]);
请注意,我在这里删除了一些不相关的ui操作代码.