简体   繁体   中英

angular2-jwt CompileMetadataResolver error

I'm introducing angular2 and json web token with angular2-JWT. I had some problems instantiating an object of the class AuthHttp

Here is my 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 { }

and my auth.service.ts

import { Injectable } from '@angular/core';

@Injectable()
export class AuthService {

  constructor(public authHttp: AuthHttp) {}

}

When I add the construtor to my service I get the below erorr

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

are you missing import { AuthHttp } from 'angular2-jwt';

in your auth.service.ts ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM