Skip to content

Add an Angular 1.3+ example of http interceptor. #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,29 @@ If you have a complicated AJAX applicaiton running, you might want to automate t
**Please that this is only a suggestion we've came up with in order to make your life easier, and might work great with some set-ups, while not working at all with others, overall, you should try it yourself and see if it's a good fit for your needs.**
There's alwasys the basic setup of calling $rootScope.htmlReady() from the controller.

Example:
Example (Angular 1.3):
```javascript
var interceptor = ['$q', '$injector', '$timeout', '$rootScope', function($q, $injector, $timeout, $rootScope) {
return {
response: function(resp) {
var $http = $injector.get('$http');
if (!$http.pendingRequests.length) {
$timeout(function() {
if (!$http.pendingRequests.length) {
$rootScope.htmlReady();
}
}, 700); // Use .7s as safety interval
}
return resp;
}
};
}];

$httpProvider.interceptors.push(interceptor);
```


Example (Angular 1.2):
```javascript
var app = angular.module('myApp', ['angular-seo'])
.config(function($routeProvider, $httpProvider){
Expand Down