我想在 $resource 中传递默认参数的动态值。请查看Plunker .在这里,当我在工厂中传递默认参数时
app.factory('myFactory', ["$resource", function($resource) {
return $resource('http://google.com', {timeStamp : (new Date()).getTime()}, {
query : {
method : 'GET',
isArray : true,
cache : false
}
})
}]);
我希望默认参数 timeStamp 是动态的。 目前,当我点击刷新按钮时,参数值总是相同(检查控制台)
I need this functionality because IE make cache on GET method and I don't want cache data
最佳答案
这应该对你有帮助。
app.factory('myFactory', ["$resource", function($resource) {
return $resource('http://google.com', {}, {
query : {
method : 'GET',
isArray : true,
params : { ts : Date.now } // <-- new timestamp will be genrated and assigned to ts
}
})
}]);
每次调用 myFactory.query()
方法时,一个带有当前时间戳值的查询字符串 ts
将出现在 url 中。
关于javascript - 如何在 Angular $resource 中传递动态参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30723878/