8

I'am trying to use a basic sample of interceptors, so I stared with a little piece of code but without success:

var app = angular.module('app',[]).
  config(['$routeProvider','$locationProvider', function($routeProvider,$location) {
    $routeProvider.
    when('/home', {templateUrl: 'home.html',   controller: homeCtrl}).
    when('/login', {templateUrl: 'login.html',   controller: loginController}).
    otherwise({redirectTo : '/home' });
}]);


app.config(function ($httpProvider) {
    $httpProvider.interceptors.push('httpRequestInterceptor');
});

When I launch my index page I have an error message in the console :

Uncaught TypeError: Cannot call method 'push' of undefined from app 

Any idea?

Thanks

1
  • 2
    Check your angularjs version and corresponding version of $http documentation. The issue may with the version. Commented Oct 14, 2013 at 16:44

2 Answers 2

12

Your code is perfect. You need to make sure you are using the correct version of angularjs. The $http.interceptors array was added in version 1.1.4.

I made a plunker with your example working with angular 1.1.4, check it out here http://plnkr.co/edit/cuPfat?p=preview

Sign up to request clarification or add additional context in comments.

Comments

5

$httpProvider.interceptors array was added in AngularJS v.1.1.4 (I believe). You're most probably using some older version of AngularJS.

Btw, that error says $httpProvider.interceptors is not defined, not $httpProvider as your title implies.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.