AngularJS $ httpProvider未定义未定义、AngularJS、httpProvider

2023-09-14 00:10:21 作者:撩人微风

我'尝试使用拦截器的基本样本,所以我用一小片code,但没有成功瞪大了眼睛:

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 

任何想法?

感谢

推荐答案

您code是完美的。你需要确保你正在使用angularjs的正确版本。在1.1.4版本中添加了$ http.interceptors阵列。

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.

我做你的榜样具有角1.1.4工作一个plunker,看看这里的http:// plnkr.co/edit/cuPfat?p=$p$pview

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

 
精彩推荐
图片推荐