首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >angular2-jwt CompileMetadataResolver错误

angular2-jwt CompileMetadataResolver错误
EN

Stack Overflow用户
提问于 2016-09-05 12:47:14
回答 1查看 451关注 0票数 1

我将引入带有angular2-JWT的angular2和json web token。我在实例化AuthHttp类的对象时遇到了一些问题

这是我的app.module.ts

代码语言:javascript
复制
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

代码语言:javascript
复制
import { Injectable } from '@angular/core';

@Injectable()
export class AuthService {

  constructor(public authHttp: AuthHttp) {}

}

当我将构造器添加到我的服务中时,我得到以下错误

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2016-09-06 08:33:55

你在想import { AuthHttp } from 'angular2-jwt';吗?

在你的auth.service.ts里?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39324084

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档