Angular 1.5.4 $http progress event

前端 未结 5 1668
滥情空心
滥情空心 2020-12-05 21:04

Now Angular 1.5.4 finally allows you to track progress event on $http provider but for some reason I keep getting the $rootScope as a response instead of an actual progress

5条回答
  •  误落风尘
    2020-12-05 21:25

    note - I have not worked with NG 1.5.4, the example below is for leveraging existing pre 1.5.4 APIs


    The notify(event) API is part of the deferred object when you call $q.defer(). I'm not sure what a practical implementation of this would be in terms of a typical get/put/post call via $http. But if you want to see it in action you can do something like this:

    some service API

    var mockRqst = function(){
        var d = $q.defer()
        var crnt = 0
    
        $off = $interval( function(){
            d.notify( crnt )
            crnt += 5
    
            if (crnt >= 100)
            {
                $interval.cancel( $off ) //cancel the interval callback
                d.resolve( "complete" )
            }
        }
    
        return d.promise
    }    
    

    using the notification

    someService.mockRqst()
    .then( thenCallback, catchCallback, function( update ){
         console.log("update", update)
    })  
    

    codepen - http://codepen.io/jusopi/pen/eZMjrK?editors=1010

    Again, I must stress that I'm not entirely sure how you can tie this into an actual external http call.

提交回复
热议问题