首页 > 解决方案 > 未捕获的类型错误:无法在 HttpXhrBackend 读取未定义的属性“方法”

问题描述

我正在关注有关使用 Angular HttpInterceptor 的教程,但是当我调用 handle() 方法时出现错误

//下一个.handle();

Uncaught TypeError: Cannot read property 'method' of undefined at HttpXhrBackend.push../node_modules/@angular/common/fesm5/http.js.HttpXhrBackend.handle (http://localhost:4200/vendor.js:31148:17) at eval (eval at push../src/app/services/authInterceptor.service.ts.AuthInterceptorService.intercept (http://localhost:4200/main.js:756:9), <anonymous>:1:6) at AuthInterceptorService.push../src/app/services/authInterceptor.service.ts.AuthInterceptorService.intercept (http://localhost:4200/main.js:756:9) at HttpInterceptorHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http://localhost:4200/vendor.js:30859:33) at HttpXsrfInterceptor.push../node_modules/@angular/common/fesm5/http.js.HttpXsrfInterceptor.intercept (http://localhost:4200/vendor.js:31450:25) at HttpInterceptorHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http://localhost:4200/vendor.js:30859:33) at HttpInterceptingHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptingHandler.handle (http://localhost:4200/vendor.js:31494:27) at MergeMapSubscriber.project (http://localhost:4200/vendor.js:30699:184) at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._tryNext (http://localhost:4200/vendor.js:143493:27) at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._next (http://localhost:4200/vendor.js:143483:18)


import { Injectable } from '@angular/core';
import { HttpInterceptor } from '@angular/common/http';

@Injectable()
export class AuthInterceptorService implements HttpInterceptor{
  intercept(req,next){
    console.log(req);
    return next.handle();
  }

}

有什么我做错了吗?,因为请求被记录了。

我正在使用 Angular 7.0.3 版

标签: angular

解决方案


请发送req手柄

intercept(req,next){
   console.log(req);
   return next.handle(req); <--- here
}

推荐阅读