TypeError:如果没有“ new”,则无法调用类构造函数AuthHeaderInterceptor

时间:2020-01-02 16:11:22

标签: angular intercept

我正在使用Angular 8构建一个简单的应用程序。

实施http-interceptor时出现以下错误:

TypeError: Class constructor AuthHeaderInterceptor cannot be invoked without 'new'
    at eval (module.ngfactory.js? [sm]:1)
    at _callFactory (core.js:30488)
    at _createProviderInstance (core.js:30429)
    at resolveNgModuleDep (core.js:30373)
    at NgModuleRef_.get (core.js:31578)
    at HttpInterceptingHandler.handle (http.js:2811)
    at MergeMapSubscriber.project (http.js:1648)
    at MergeMapSubscriber._tryNext (mergeMap.js:46)
    at MergeMapSubscriber._next (mergeMap.js:36)
    at MergeMapSubscriber.next (Subscriber.js:49)

我已经找到了在线解决方案,可以将目标从ES2015更改为ES5。在此之后,我得到了错误:

TypeError: Cannot read property 'intercept' of undefined
    at HttpInterceptorHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http.js:1279)
    at HttpXsrfInterceptor.push../node_modules/@angular/common/fesm5/http.js.HttpXsrfInterceptor.intercept (http.js:1888)
    at HttpInterceptorHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http.js:1279)
    at HttpInterceptingHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptingHandler.handle (http.js:1932)
    at MergeMapSubscriber.project (http.js:1099)
    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._tryNext (mergeMap.js:61)
    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._next (mergeMap.js:51)
    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:53)
    at Observable._subscribe (scalar.js:5)
    at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (Observable.js:43)

Here is my Code

0 个答案:

没有答案