首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >使用angularjs拦截器将数据实时发送到工厂外

使用angularjs拦截器将数据实时发送到工厂外
EN

Stack Overflow用户
提问于 2019-03-21 12:37:09
回答 1查看 34关注 0票数 1

我想解决如何使用$scope.time到我的html。我想在UI中显示上一次http请求的时间,但显示了一个错误。我不能用$scope

我有这些代码:

代码语言:javascript
代码运行次数:0
运行
复制
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;}];

配置:

代码语言:javascript
代码运行次数:0
运行
复制
module.config(function ($httpProvider) {
$httpProvider.interceptors.push('timestamp');}
EN

回答 1

Stack Overflow用户

发布于 2019-03-21 12:43:34

尝试返回$scope.time或在任何变量中获取时间,并尝试访问它

代码语言:javascript
代码运行次数:0
运行
复制
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;}];

控制器

代码语言:javascript
代码运行次数:0
运行
复制
module.config(function ($httpProvider) {
$httpProvider.interceptors.push('timestamp');}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55273873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档