我想解决如何使用$scope.time
到我的html。我想在UI中显示上一次http请求的时间,但显示了一个错误。我不能用$scope
。
我有这些代码:
module.factory('timestamp', [function ($scope) {
var time = {
request: function (config) {
$scope.time = new Date().getTime(); //wanted to show in UI realtime
return config;
}
//,response: function (response) {
// response.config.responseTimestamp = new Date().getTime();
// return response;
//}
};
return time;}];
配置:
module.config(function ($httpProvider) {
$httpProvider.interceptors.push('timestamp');}
发布于 2019-03-21 04:43:34
尝试返回$scope.time或在任何变量中获取时间,并尝试访问它
module.factory('timestamp', [function ($scope) {
var time = {
request: function (config) {
config.requestTimestamp = new Date().getTime();
return config;
},
response: function(response) {
response.config.responseTimestamp = new Date().getTime();
return response;
}
};
return time;}];
控制器
module.config(function ($httpProvider) {
$httpProvider.interceptors.push('timestamp');}
https://stackoverflow.com/questions/55273873
复制