Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ _The loader should be now visible at least 2 seconds, independent of the total h
dispatched. Should the total amount of time of the request(s) be larger than the ttl,
the loader will dismiss when the last http request is done._

### Per-request use of HTTP Loader

The HTTP loader can also be enabled or disabled by passing the $useHttpLoader parameter to the $http config object.

```javascript
$http.get('/someUrl', {
params: {$useHttpLoader: true}, // will enable/disable http loader for this request regardless of whitelist
});

// or with a resource...
var User = $resource('/user/:userId', {userId:'@id', $useHttpLoader: true}); // default to always using the HTTP loader
var user = User.get(
{userId:123, $useHttpLoader: false}, // this call overrides default parameter defined above
function() {
user.abc = true;
user.$save();
}
);
```

Contributing
------------

Expand Down
14 changes: 11 additions & 3 deletions app/package/js/angular-http-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ angular
* The response configuration
*/
var checkAndHide = function (config) {
if (isUrlOnWhitelist(config.url) &&
(--numLoadings) === 0) {
if (config.useHttpLoader && (--numLoadings) === 0) {
$rootScope.$emit('loaderHide', config.method);
}
};
Expand All @@ -206,8 +205,17 @@ angular
* @returns {object|Promise}
*/
request: function (config) {
if (isUrlOnWhitelist(config.url)) {
var useHttpLoaderFlagDefined =
angular.isObject(config.params) &&
angular.isDefined(config.params.$useHttpLoader);
if (isUrlOnWhitelist(config.url) &&
(!useHttpLoaderFlagDefined ||
(useHttpLoaderFlagDefined && config.params.$useHttpLoader))) {
numLoadings++;
if (useHttpLoaderFlagDefined) {
delete config.params.$useHttpLoader; // remove flag from params
}
config.useHttpLoader = true;
$rootScope.$emit('loaderShow', config.method);
}

Expand Down
2 changes: 1 addition & 1 deletion app/package/js/angular-http-loader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions app/src/js/httpMethodInterceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ angular
* The response configuration
*/
var checkAndHide = function (config) {
if (isUrlOnWhitelist(config.url) &&
(--numLoadings) === 0) {
if (config.useHttpLoader && (--numLoadings) === 0) {
$rootScope.$emit('loaderHide', config.method);
}
};
Expand All @@ -78,8 +77,17 @@ angular
* @returns {object|Promise}
*/
request: function (config) {
if (isUrlOnWhitelist(config.url)) {
var useHttpLoaderFlagDefined =
angular.isObject(config.params) &&
angular.isDefined(config.params.$useHttpLoader);
if (isUrlOnWhitelist(config.url) &&
(!useHttpLoaderFlagDefined ||
(useHttpLoaderFlagDefined && config.params.$useHttpLoader))) {
numLoadings++;
if (useHttpLoaderFlagDefined) {
delete config.params.$useHttpLoader; // remove flag from params
}
config.useHttpLoader = true;
$rootScope.$emit('loaderShow', config.method);
}

Expand Down