Skip to content
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

How to get this to work with Angular 1.3.6 #30

Open
hayatnoor opened this issue Apr 21, 2015 · 2 comments
Open

How to get this to work with Angular 1.3.6 #30

hayatnoor opened this issue Apr 21, 2015 · 2 comments

Comments

@hayatnoor
Copy link

Angular's $httpProvider.responseInterceptors is deprecated. I tried to use the new version which is $httpProvider.interceptors, but I cannot seem to get this to work. When I curl the application, I receive the original template.

@hayatnoor
Copy link
Author

This is my config module:

//Setting up route
app.config(['$locationProvider', '$httpProvider', function($locationProvider, $httpProvider) {
$locationProvider.hashPrefix('!');

$httpProvider.interceptors.push(function ($q, $injector, dependency1, dependency2) {
    return {

        'response': function (response) {
            var $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;
            // same as above
        }
    };
});

}]);

@mlent
Copy link

mlent commented Dec 1, 2015

Hey, in case you are still having problems with this (or anyone else needs an updated example), here's what I have, which works:

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);

However, if you're still getting the original template, its unlikely that this is the problem -- because the 10s timeout in the phantomjs script is probably sufficient for your HTML to get rendered. For me, when I had the old example and this was not doing anything, my template was still rendering, it just took 10s each time. Now it takes ~4s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants