Skip to content

Commit

Permalink
Merge pull request steeve#13 from BeOleg/htmlReady_additional_docs
Browse files Browse the repository at this point in the history
Added additional docs for htmlReady() function
  • Loading branch information
steeve committed Feb 19, 2015
2 parents a055160 + 1eea6ac commit d6b50c5
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,49 @@ function MyCtrl($scope) {
}
```

If you have a complicated AJAX applicaiton running, you might want to automate this proccess, and call this function on the config level.

**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:
```javascript
var app = angular.module('myApp', ['angular-seo'])
.config(function($routeProvider, $httpProvider){
$locationProvider.hashPrefix('!');
$routeProvider.when({...});

var $http,
interceptor = ['$q', '$injector', function ($q, $injector) {
var error;
function success(response) {
$http = $http || $injector.get('$http');
var $timeout = $injector.get('$timeout');
var $rootScope = $injector.get('$rootScope');
if($http.pendingRequests.length < 1) {
$timeout(function(){
if($http.pendingRequests.length < 1){
$rootScope.htmlReady();
}
}, 700);//an 0.7 seconds safety interval, if there are no requests for 0.7 seconds, it means that the app is through rendering
}
return response;
}

function error(response) {
$http = $http || $injector.get('$http');

return $q.reject(response);
}

return function (promise) {
return promise.then(success, error);
}
}];

$httpProvider.responseInterceptors.push(interceptor);
```
And that's all there is to do on the app side.
Expand Down

0 comments on commit d6b50c5

Please sign in to comment.