角JS - 听或绑定$ http请求 [英] Angular JS - listen or bind $http request

查看:130
本文介绍了角JS - 听或绑定$ http请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有听/每次绑定一个事件有一个$ http请求并收到响应后也?一个办法

Is there a way to listen/bind an event every time there's an $http request and also after it receives a response?

其实我提供我自己的事件和监听器手工完成它,但我只是好奇,如果已经有一个在JS角本?

Actually I've done it manually by providing my own events and listeners, but I'm just curious if there's already a listener in Angular JS for this?

为什么我想这样做的原因是,每次我的应用程序发送的时间/执行$ http请求我想表明我的加载屏幕,表明应用程序是获取它收到响应之后,数据然后将其隐藏。

The reason why I wanted to do this is that, every time my application sends/execute an $http request I wanted to show my loading screen to indicate that the app is retrieving data then hide it after it receives a response.

谢谢!

推荐答案

您可以使用角加载酒吧。它自动加载栏的进步,通过采用了棱角分明的拦截器。在同一时期内的多个请求将捆绑在一起,使得每个响应由加适量的进度条。

You can use Angular Loading Bar. It automates the loading bar's progress, by using angular interceptors. Multiple requests within the same time period get bundled together such that each response increments the progress bar by the appropriate amount.

    app.config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {
        cfpLoadingBarProvider.includeSpinner = false; // second boot loader, you can show or hide
        cfpLoadingBarProvider.includeBar = true; // main loader
        cfpLoadingBarProvider.latencyThreshold = 200; // delay
    }])

希望这有助于...

hope this helps...

这篇关于角JS - 听或绑定$ http请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆