AngularJS $ httpProvider undefined

I am trying to use a basic interceptor pattern, so I looked with a small piece of code, but to no avail:

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, an error message appears in the console:

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

Any idea?

thanks

+8
angularjs
source share
2 answers

Your code is beautiful. You must make sure that you are using the correct version of angularjs. An array of $ http.interceptors was added in version 1.1.4.

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

+12
source

$httpProvider.interceptors array was added in AngularJS v.1.1.4 (I believe). Most likely you are using an outdated version of AngularJS.

Btw, this error says that $httpProvider.interceptors not defined, not $httpProvider , as the name suggests.

+5
source

All Articles