我正在使用 angular2-JWT 介绍 angular2 和 json Web 令牌。我在实例化 AuthHttp 类的对象时遇到了一些问题
这是我的 app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HTTP_PROVIDERS, Http } from '@angular/http';
import { AuthHttp, AuthConfig, AUTH_PROVIDERS, provideAuth } from 'angular2-jwt';
import { AppComponent } from './app.component';
import { IndexComponent } from './Components/Index/index.component';
import { AuthService } from './Services/auth.service';
import { routing } from './app.routing';
@NgModule({
imports: [
BrowserModule,
routing,
],
declarations: [
AppComponent,
IndexComponent,
],
providers: [
AuthService,
AuthHttp,
provideAuth({
headerName: 'Authorization',
headerPrefix: 'bearer',
tokenName: 'token',
tokenGetter: (() => localStorage.getItem('id_token')),
globalHeaders: [{ 'Content-Type': 'application/json' }],
noJwtError: true
})
]
bootstrap: [AppComponent]
})
export class AppModule { }
和我的 auth.service.ts
import { Injectable } from '@angular/core';
@Injectable()
export class AuthService {
constructor(public authHttp: AuthHttp) {}
}
当我将构造函数添加到我的服务时,我得到以下错误
Error: CompileMetadataResolver</CompileMetadataResolver.prototype.getDependenciesMetadata@http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14388:1
CompileMetadataResolver</CompileMetadataResolver.prototype.getTypeMetadata@http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14285:23
CompileMetadataResolver</CompileMetadataResolver.prototype.getProvidersMetadata/<@http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14432:37
CompileMetadataResolver</CompileMetadataResolver.prototype.getProvidersMetadata@http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14412:11
CompileMetadataResolver</CompileMetadataResolver.prototype.getNgModuleMetadata@http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14173:55
RuntimeCompiler</RuntimeCompiler.prototype._compileComponents@http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:16777:26
RuntimeCompiler</RuntimeCompiler.prototype._compileModuleAndComponents@http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:16715:34
RuntimeCompiler</RuntimeCompiler.prototype.compileModuleAsync@http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:16706:18
PlatformRef_</PlatformRef_.prototype._bootstrapModuleWithZone@http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:9488:20
PlatformRef_</PlatformRef_.prototype.bootstrapModule@http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:9470:20
@http://localhost:3000/app/main.js:4:1
@http://localhost:3000/app/main.js:1:1
@http://localhost:3000/app/main.js:1:1
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:332:20
Zone</Zone</Zone.prototype.run@http://localhost:3000/node_modules/zone.js/dist/zone.js:225:25
scheduleResolveOrReject/<@http://localhost:3000/node_modules/zone.js/dist/zone.js:591:53
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:365:24
Zone</Zone</Zone.prototype.runTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:265:29
drainMicroTaskQueue@http://localhost:3000/node_modules/zone.js/dist/zone.js:497:26
ZoneTask/this.invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:437:26
Evaluating http://localhost:3000/app/main.js
Error loading http://localhost:3000/app/main.js