Setting global http timeout in angular.js

We know to set HTTP timeout,

$http.get(‘path/to/service’,{timeout:5000});

For setting global HTTP timeout in angular.js. $http will not appreciate default setting it in httpProvider. With bleeding edge angular.js setting timeout is possible.

angular.module('yourapp')

  .factory('timeoutHttpIntercept', function ($rootScope, $q) {

    return {

      'request': function(config) {

        config.timeout = 10000;

        return config;

      }

    };

 });

$httpProvider.interceptors.push('timeoutHttpIntercept');