$ cnpm install ng-http-estimate
Automatic $http request time estimates
Demo, basic example, custom estimator, reporting accuracy, low-level
npm|bower install ng-http-estimate
Include 'dist/ng-http-estimate.js' script in your page and add dependency on 'http-estimate'
angular.module('app', ['http-estimate']);
Place the loading element into the body, you can also style it
<body>
<http-estimate></http-estimate>
...
</body>
The element will appear automatically on HTML requests and will show estimated remaining time (if previously computed) or "loading ..." message. Optionally, include 'dist/ng-http-estimate.css' file to get the default centered style.
.config(function (httpEstimateProvider) {
httpEstimateProvider.set({
interceptHttp: false
});
})
.config(function (httpEstimateProvider) {
httpEstimateProvider.set({
estimator: function (cacheEstimator, url) {
console.log('need to estimate how long get request to', url, 'would take');
var estimate = cacheEstimator(url);
console.log('built-in cache estimator says', estimate);
console.log('will trust it');
return estimate;
}
});
})
.config(function (httpEstimateProvider) {
httpEstimateProvider.set({
estimator: function (cacheEstimator, url) {
...
},
accuracy: function (url, estimate, took) {
console.log('estimated request to', url, 'to take', estimate, 'took', took, 'ms');
}
});
})
start(name)
and stop(name)
. Great for custom duration estimation with http intercepts disabled..controller('demoController', function ($scope, httpEstimateLowLevel) {
$scope.startLoad = function startLoad() {
httpEstimateLowLevel.start('/foo/bar');
};
$scope.stopLoad = function stopLoad() {
httpEstimateLowLevel.stop('/foo/bar');
};
});
.config(function (httpEstimateProvider) {
httpEstimateProvider.set({
verbose: true
});
})
Author: Gleb Bahmutov © 2015
License: MIT - do anything with the code, but don't blame me if it does not work.
Spread the word: tweet, star on github, etc.
Support: if you find any problems with this module, email / tweet / open issue on Github
Copyright 2014 - 2017 © taobao.org |