我正在使用http拦截器。当我发出 Restangular GET 请求时,我确实看到了所有值。这是我的请求拦截器的代码。
request: function (config) {
// see link below to see value of config
console.log('config', config);
// below returns full url except query string
console.log('location', $location.absUrl());
// $rootScope.cacheData is $cacheFactory
console.log('$rootScope', $rootScope.cacheData);
// only returns {id: "http", size: 3}
console.log('cache info', $rootScope.cacheData.info());
// below returns undefined
console.log('cache get', $rootScope.cacheData.get('http'));
// other codes removed since it's not related
// ........
// ........
// Return the config or wrap it in a promise if blank.
return config || $q.when(config);
},
配置值:http: //i.imgur.com/l0IsXbJ.png
不幸的是,准备手动捕获的参数并不能 100% 保证它会匹配缓存的内容。我注意到 cacheFactory 会检查所请求的确切字符串。因此,如果我们的 GET 请求的查询参数是 age=12&name=scott,那么在我们的 http 拦截器上,我们以另一种方式准备它,将 name 先放在 age(name=scott&age=12) 之前,cacheFactory 将找不到它。
所以我试图寻找一个角度服务或工厂,它将返回与我们提出的请求相等的完整 URL。我试过 $location 但它没有给出完整的 GET 请求。